diff options
author | Alan Modra <amodra@gmail.com> | 2017-09-26 11:28:04 +0930 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2017-09-26 13:39:35 +0930 |
commit | 66cfc0fd0d9daadc2dac5a783b69b4050c0b1722 (patch) | |
tree | c4bfe4c81311d9fd53ab1ce6e81b676554ee6689 /binutils/readelf.c | |
parent | 6c3e20f177102519cf4f8b3c7e7e17996ed7cd7f (diff) | |
download | gdb-66cfc0fd0d9daadc2dac5a783b69b4050c0b1722.zip gdb-66cfc0fd0d9daadc2dac5a783b69b4050c0b1722.tar.gz gdb-66cfc0fd0d9daadc2dac5a783b69b4050c0b1722.tar.bz2 |
PR21732, String-concatenated message can not be translated
Preprocessor tokens like DWARF_VMA_FMT and BFD_VMA_FMT are not
understood by gettext, and cause the translation string to be
truncated. Even if it were not truncated, we wouldn't want a value
that changes depending on host or configure options to be put in a
translation string.
PR 21732
* dwarf.c (READ_ULEB): Don't use DWARF_VMA_FMT in translated string.
(READ_SLEB): Likewise.
* readelf.c (bfd_vmatoa): New function.
(get_data, get_dynamic_data): Use it for printing error messages.
Diffstat (limited to 'binutils/readelf.c')
-rw-r--r-- | binutils/readelf.c | 72 |
1 files changed, 46 insertions, 26 deletions
diff --git a/binutils/readelf.c b/binutils/readelf.c index 9a8226f..3e5ad0e 100644 --- a/binutils/readelf.c +++ b/binutils/readelf.c @@ -321,6 +321,30 @@ static const char * get_symbol_version_string } \ while (0) +/* Print a BFD_VMA to an internal buffer, for use in error messages. + BFD_FMA_FMT can't be used in translated strings. */ + +static const char * +bfd_vmatoa (char *fmtch, bfd_vma value) +{ + /* bfd_vmatoa is used more then once in a printf call for output. + Cycle through an array of buffers. */ + static int buf_pos = 0; + static struct bfd_vmatoa_buf + { + char place[64]; + } buf[4]; + char *ret; + char fmt[32]; + + ret = buf[buf_pos++].place; + buf_pos %= ARRAY_SIZE (buf); + + sprintf (fmt, "%%%s%s", BFD_VMA_FMT, fmtch); + snprintf (ret, sizeof (buf[0].place), fmt, value); + return ret; +} + /* Retrieve NMEMB structures, each SIZE bytes long from FILE starting at OFFSET + the offset of the current archive member, if we are examining an archive. Put the retrieved data into VAR, if it is not NULL. Otherwise allocate a buffer @@ -347,9 +371,9 @@ get_data (void * var, FILE * file, unsigned long offset, bfd_size_type size, || (bfd_size_type) ((size_t) nmemb) != nmemb)) { if (reason) - error (_("Size truncation prevents reading 0x%" BFD_VMA_FMT "x" - " elements of size 0x%" BFD_VMA_FMT "x for %s\n"), - nmemb, size, reason); + error (_("Size truncation prevents reading %s" + " elements of size %s for %s\n"), + bfd_vmatoa ("u", nmemb), bfd_vmatoa ("u", size), reason); return NULL; } @@ -357,9 +381,9 @@ get_data (void * var, FILE * file, unsigned long offset, bfd_size_type size, if (amt < nmemb) { if (reason) - error (_("Size overflow prevents reading 0x%" BFD_VMA_FMT "x" - " elements of size 0x%" BFD_VMA_FMT "x for %s\n"), - nmemb, size, reason); + error (_("Size overflow prevents reading %s" + " elements of size %s for %s\n"), + bfd_vmatoa ("u", nmemb), bfd_vmatoa ("u", size), reason); return NULL; } @@ -369,9 +393,8 @@ get_data (void * var, FILE * file, unsigned long offset, bfd_size_type size, || offset + archive_file_offset + amt > current_file_size) { if (reason) - error (_("Reading 0x%" BFD_VMA_FMT "x" - " bytes extends past end of file for %s\n"), - amt, reason); + error (_("Reading %s bytes extends past end of file for %s\n"), + bfd_vmatoa ("u", amt), reason); return NULL; } @@ -394,9 +417,8 @@ get_data (void * var, FILE * file, unsigned long offset, bfd_size_type size, if (mvar == NULL) { if (reason) - error (_("Out of memory allocating 0x%" BFD_VMA_FMT "x" - " bytes for %s\n"), - amt, reason); + error (_("Out of memory allocating %s bytes for %s\n"), + bfd_vmatoa ("u", amt), reason); return NULL; } @@ -406,8 +428,8 @@ get_data (void * var, FILE * file, unsigned long offset, bfd_size_type size, if (fread (mvar, (size_t) size, (size_t) nmemb, file) != nmemb) { if (reason) - error (_("Unable to read in 0x%" BFD_VMA_FMT "x bytes of %s\n"), - amt, reason); + error (_("Unable to read in %s bytes of %s\n"), + bfd_vmatoa ("u", amt), reason); if (mvar != var) free (mvar); return NULL; @@ -10957,9 +10979,8 @@ get_dynamic_data (FILE * file, bfd_size_type number, unsigned int ent_size) if (sizeof (size_t) < sizeof (bfd_size_type) && (bfd_size_type) ((size_t) number) != number) { - error (_("Size truncation prevents reading %" BFD_VMA_FMT "u" - " elements of size %u\n"), - number, ent_size); + error (_("Size truncation prevents reading %s elements of size %u\n"), + bfd_vmatoa ("u", number), ent_size); return NULL; } @@ -10967,23 +10988,23 @@ get_dynamic_data (FILE * file, bfd_size_type number, unsigned int ent_size) attempting to allocate memory when the read is bound to fail. */ if (ent_size * number > current_file_size) { - error (_("Invalid number of dynamic entries: %" BFD_VMA_FMT "u\n"), - number); + error (_("Invalid number of dynamic entries: %s\n"), + bfd_vmatoa ("u", number)); return NULL; } e_data = (unsigned char *) cmalloc ((size_t) number, ent_size); if (e_data == NULL) { - error (_("Out of memory reading %" BFD_VMA_FMT "u dynamic entries\n"), - number); + error (_("Out of memory reading %s dynamic entries\n"), + bfd_vmatoa ("u", number)); return NULL; } if (fread (e_data, ent_size, (size_t) number, file) != number) { - error (_("Unable to read in %" BFD_VMA_FMT "u bytes of dynamic data\n"), - number * ent_size); + error (_("Unable to read in %s bytes of dynamic data\n"), + bfd_vmatoa ("u", number * ent_size)); free (e_data); return NULL; } @@ -10991,9 +11012,8 @@ get_dynamic_data (FILE * file, bfd_size_type number, unsigned int ent_size) i_data = (bfd_vma *) cmalloc ((size_t) number, sizeof (*i_data)); if (i_data == NULL) { - error (_("Out of memory allocating space for %" BFD_VMA_FMT "u" - " dynamic entries\n"), - number); + error (_("Out of memory allocating space for %s dynamic entries\n"), + bfd_vmatoa ("u", number)); free (e_data); return NULL; } |