Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | Upstream-Status: Backport |
| 2 | |
| 3 | nm: Fix size passed to snprintf for invalid sh_name case. |
| 4 | native build failed as following on Fedora18: |
| 5 | nm.c: In function 'show_symbols_sysv': |
| 6 | nm.c:756:27: error: argument to 'sizeof' in 'snprintf' call is the same expression as the destination; did you mean to provide an explicit length? [-Werror=sizeof-pointer-memaccess] |
| 7 | snprintf (name, sizeof name, "[invalid sh_name %#" PRIx32 "]", |
| 8 | ^ |
| 9 | |
| 10 | The original commit is http://git.fedorahosted.org/cgit/elfutils.git/commit/src/nm.c?id=57bd66cabf6e6b9ecf622cdbf350804897a8df58 |
| 11 | |
| 12 | Signed-off-by: Zhenhua Luo <zhenhua.luo@freescale.com> |
| 13 | |
| 14 | --- elfutils-0.148/src/nm.c.org 2013-03-11 22:36:11.000000000 -0500 |
| 15 | +++ elfutils-0.148/src/nm.c 2013-03-11 22:46:09.000000000 -0500 |
| 16 | @@ -752,8 +752,9 @@ |
| 17 | gelf_getshdr (scn, &shdr_mem)->sh_name); |
| 18 | if (unlikely (name == NULL)) |
| 19 | { |
| 20 | - name = alloca (sizeof "[invalid sh_name 0x12345678]"); |
| 21 | - snprintf (name, sizeof name, "[invalid sh_name %#" PRIx32 "]", |
| 22 | + const size_t bufsz = sizeof "[invalid sh_name 0x12345678]"; |
| 23 | + name = alloca (bufsz); |
| 24 | + snprintf (name, bufsz, "[invalid sh_name %#" PRIx32 "]", |
| 25 | gelf_getshdr (scn, &shdr_mem)->sh_name); |
| 26 | } |
| 27 | scnnames[elf_ndxscn (scn)] = name; |