diff options
author | 2017-03-03 13:41:41 -0800 | |
---|---|---|
committer | 2018-06-07 10:05:50 -0400 | |
commit | 9c0ec154d782795daa3b7d2ae273bbda2b36ae83 (patch) | |
tree | cb84d48a81250e9d9139359de81be357bb750a5a /scanelf.c | |
parent | paxelf: constify elfobj pointer in helpers (diff) | |
download | pax-utils-9c0ec154d782795daa3b7d2ae273bbda2b36ae83.tar.gz pax-utils-9c0ec154d782795daa3b7d2ae273bbda2b36ae83.tar.bz2 pax-utils-9c0ec154d782795daa3b7d2ae273bbda2b36ae83.zip |
scanelf: use asprintf instead of manual malloc/sprintf
This makes the code a bit nicer to deal with. For portable targets,
we already include asprintf from gnulib.
Diffstat (limited to 'scanelf.c')
-rw-r--r-- | scanelf.c | 12 |
1 files changed, 7 insertions, 5 deletions
@@ -733,19 +733,21 @@ static const char *scanelf_file_textrels(elfobj *elf, char *found_textrels, char if (be_verbose && objdump) { \ Elf ## B ## _Addr end_addr = offset_tmp + EGET(func->st_size); \ char *sysbuf; \ - size_t syslen; \ - const char sysfmt[] = "%s -r -R -d -w -l --start-address=0x%lX --stop-address=0x%lX %s | grep --color -i -C 3 '.*[[:space:]]%lX:[[:space:]]*R_.*'\n"; \ - syslen = sizeof(sysfmt) + strlen(objdump) + strlen(elf->filename) + 3 * sizeof(unsigned long) + 1; \ - sysbuf = xmalloc(syslen); \ + int ret; \ if (end_addr < r_offset) \ /* not uncommon when things are optimized out */ \ end_addr = r_offset + 0x100; \ - snprintf(sysbuf, syslen, sysfmt, \ + ret = asprintf( \ + &sysbuf, \ + "%s -r -R -d -w -l --start-address=0x%lX --stop-address=0x%lX %s | " \ + "grep --color -i -C 3 '.*[[:space:]]%lX:[[:space:]]*R_.*'\n", \ objdump, \ (unsigned long)offset_tmp, \ (unsigned long)end_addr, \ elf->filename, \ (unsigned long)r_offset); \ + if (ret < 0) \ + errp("asprintf() failed"); \ fflush(stdout); \ if (system(sysbuf)) {/* don't care */} \ fflush(stdout); \ |