]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
i18n: Format large integers before the translation message
authorMiguel Ángel Arruga Vivas <rosen644835@gmail.com>
Sat, 3 Apr 2021 13:33:33 +0000 (15:33 +0200)
committerDaniel Kiper <daniel.kiper@oracle.com>
Tue, 13 Apr 2021 15:16:04 +0000 (17:16 +0200)
The GNU gettext only supports the ISO C99 macros for integral
types. If there is a need to use unsupported formatting macros,
e.g. PRIuGRUB_UINT64_T, according to [1] the number to a string
conversion should be separated from the code printing message
requiring the internationalization. So, the function grub_snprintf()
is used to print the numeric values to an intermediate buffer and
the internationalized message contains a string format directive.

[1] https://www.gnu.org/software/gettext/manual/html_node/Preparing-Strings.html#No-string-concatenation

Signed-off-by: Miguel Ángel Arruga Vivas <rosen644835@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
grub-core/disk/luks2.c
grub-core/efiemu/i386/loadcore64.c
grub-core/kern/arm64/dl.c
grub-core/kern/ia64/dl.c
grub-core/kern/riscv/dl.c
grub-core/kern/sparc64/dl.c
grub-core/kern/x86_64/dl.c

index 125e8609ab11249369a62fb60215569e1bf9c1a0..371a53b837da6d6515d206e22737a5673d9e6809 100644 (file)
@@ -612,6 +612,7 @@ luks2_recover_key (grub_disk_t source,
   /* Try all keyslot */
   for (json_idx = 0; json_idx < size; json_idx++)
     {
+      char indexstr[21]; /* log10(2^64) ~ 20, plus NUL character. */
       typeof (source->total_sectors) max_crypt_sectors = 0;
 
       grub_errno = GRUB_ERR_NONE;
@@ -732,11 +733,12 @@ luks2_recover_key (grub_disk_t source,
          continue;
        }
 
+      grub_snprintf (indexstr, sizeof (indexstr) - 1, "%" PRIuGRUB_UINT64_T, keyslot.idx);
       /*
        * TRANSLATORS: It's a cryptographic key slot: one element of an array
        * where each element is either empty or holds a key.
        */
-      grub_printf_ (N_("Slot \"%" PRIuGRUB_UINT64_T "\" opened\n"), keyslot.idx);
+      grub_printf_ (N_("Slot \"%s\" opened\n"), indexstr);
 
       candidate_key_len = keyslot.key_size;
       break;
index 7316efc39060dbcad063583bb8d8619b923868d9..ae476ef2ce5c2a6fe0eb098d65c57e22382e73d6 100644 (file)
@@ -121,10 +121,14 @@ grub_arch_efiemu_relocate_symbols64 (grub_efiemu_segment_t segs,
                      return err;
                     break;
                  default:
-                   return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
-                                      N_("relocation 0x%" PRIxGRUB_UINT64_T
-                                         " is not implemented yet"),
-                                      ELF_R_TYPE (rel->r_info));
+                   {
+                     char rel_info[17]; /* log16(2^64) = 16, plus NUL. */
+
+                     grub_snprintf (rel_info, sizeof (rel_info) - 1, "%" PRIxGRUB_UINT64_T,
+                                    ELF_R_TYPE (rel->r_info));
+                     return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
+                                        N_("relocation 0x%s is not implemented yet"), rel_info);
+                   }
                  }
              }
          }
index 40167237419066b43b65bbbfe182b0cc7dc67940..512e5a80b03590c6d60737579529b9389f0ea4a6 100644 (file)
@@ -183,10 +183,14 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr,
          break;
 
        default:
-         return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
-                            N_("relocation 0x%" PRIxGRUB_UINT64_T
-                               " is not implemented yet"),
-                            ELF_R_TYPE (rel->r_info));
+         {
+           char rel_info[17]; /* log16(2^64) = 16, plus NUL. */
+
+           grub_snprintf (rel_info, sizeof (rel_info) - 1, "%" PRIxGRUB_UINT64_T,
+                          ELF_R_TYPE (rel->r_info));
+           return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
+                              N_("relocation 0x%s is not implemented yet"), rel_info);
+         }
        }
     }
 
index b19706c500d5671a6b40d72ae036265439da46cd..db59300fea3ceec9c30c05cfce0567b0bddd34bb 100644 (file)
@@ -136,10 +136,14 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr,
        case R_IA64_LDXMOV:
          break;
        default:
-         return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
-                            N_("relocation 0x%" PRIxGRUB_UINT64_T
-                               " is not implemented yet"),
-                            ELF_R_TYPE (rel->r_info));
+         {
+           char rel_info[17]; /* log16(2^64) = 16, plus NUL. */
+
+           grub_snprintf (rel_info, sizeof (rel_info) - 1, "%" PRIxGRUB_UINT64_T,
+                          ELF_R_TYPE (rel->r_info));
+           return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
+                              N_("relocation 0x%s is not implemented yet"), rel_info);
+         }
        }
     }
   return GRUB_ERR_NONE;
index d78297eee29b7a1391fd975f1fe8f605810dedbe..f26b12aaa4c67898a21bd494946ce80d994a662d 100644 (file)
@@ -330,10 +330,14 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr,
        case R_RISCV_RELAX:
          break;
        default:
-         return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
-                            N_("relocation 0x%" PRIxGRUB_UINT64_T
-                               " is not implemented yet"),
-                            (grub_uint64_t) ELF_R_TYPE (rel->r_info));
+         {
+           char rel_info[17]; /* log16(2^64) = 16, plus NUL. */
+
+           grub_snprintf (rel_info, sizeof (rel_info) - 1, "%" PRIxGRUB_UINT64_T,
+                          (grub_uint64_t) ELF_R_TYPE (rel->r_info));
+           return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
+                              N_("relocation 0x%s is not implemented yet"), rel_info);
+         }
        }
     }
 
index bbcce8ed5078d4c2fc850a63f58a1f1cfd0119dd..f3d960186ba56b9b4658a444d7ac1fa61f6bcf01 100644 (file)
@@ -176,10 +176,14 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr,
               & 0x1fff);
          break;
        default:
-         return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
-                            N_("relocation 0x%" PRIxGRUB_UINT64_T
-                               " is not implemented yet"),
-                            ELF_R_TYPE (rel->r_info));
+         {
+           char rel_info[17]; /* log16(2^64) = 16, plus NUL. */
+
+           grub_snprintf (rel_info, sizeof (rel_info) - 1, "%" PRIxGRUB_UINT64_T,
+                          ELF_R_TYPE (rel->r_info));
+           return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
+                              N_("relocation 0x%s is not implemented yet"), rel_info);
+         }
        }
     }
 
index 1af5a0eeb39cb5f8d75d9575db63ca580a92c836..e5a8bdcf4f96c8f1e877953018bfaf411cd9c0df 100644 (file)
@@ -106,10 +106,14 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr,
          break;
 
        default:
-         return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
-                            N_("relocation 0x%" PRIxGRUB_UINT64_T
-                               " is not implemented yet"),
-                            ELF_R_TYPE (rel->r_info));
+         {
+           char rel_info[17]; /* log16(2^64) = 16, plus NUL. */
+
+           grub_snprintf (rel_info, sizeof (rel_info) - 1, "%" PRIxGRUB_UINT64_T,
+                          ELF_R_TYPE (rel->r_info));
+           return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
+                              N_("relocation 0x%s is not implemented yet"), rel_info);
+         }
        }
     }