commit:     9c0ec154d782795daa3b7d2ae273bbda2b36ae83
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Fri Mar  3 21:41:41 2017 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Thu Jun  7 14:05:50 2018 +0000
URL:        https://gitweb.gentoo.org/proj/pax-utils.git/commit/?id=9c0ec154

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.

 scanelf.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/scanelf.c b/scanelf.c
index 01c730e..6dcc51e 100644
--- a/scanelf.c
+++ b/scanelf.c
@@ -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); \

Reply via email to