From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id C0D44138334 for ; Thu, 7 Jun 2018 14:09:48 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 00E5AE0B0C; Thu, 7 Jun 2018 14:09:47 +0000 (UTC) Received: from smtp.gentoo.org (dev.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id A9F2AE0B01 for ; Thu, 7 Jun 2018 14:09:46 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 6C42C335C9C for ; Thu, 7 Jun 2018 14:09:44 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 47D052CC for ; Thu, 7 Jun 2018 14:09:41 +0000 (UTC) From: "Mike Frysinger" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Mike Frysinger" Message-ID: <1528380350.9c0ec154d782795daa3b7d2ae273bbda2b36ae83.vapier@gentoo> Subject: [gentoo-commits] proj/pax-utils:master commit in: / X-VCS-Repository: proj/pax-utils X-VCS-Files: scanelf.c X-VCS-Directories: / X-VCS-Committer: vapier X-VCS-Committer-Name: Mike Frysinger X-VCS-Revision: 9c0ec154d782795daa3b7d2ae273bbda2b36ae83 X-VCS-Branch: master Date: Thu, 7 Jun 2018 14:09:41 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 2f6b7ce1-1ebd-4b03-b33a-b7a3843edc82 X-Archives-Hash: 2484fb301dafc577b6148e3434909575 commit: 9c0ec154d782795daa3b7d2ae273bbda2b36ae83 Author: Mike Frysinger gentoo org> AuthorDate: Fri Mar 3 21:41:41 2017 +0000 Commit: Mike Frysinger gentoo 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); \