From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from purple.birch.relay.mailchannels.net (purple.birch.relay.mailchannels.net [23.83.209.150]) by sourceware.org (Postfix) with ESMTPS id BE4633858D20 for ; Thu, 25 May 2023 01:07:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BE4633858D20 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gotplt.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gotplt.org X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 81A1E261982; Thu, 25 May 2023 01:07:36 +0000 (UTC) Received: from pdx1-sub0-mail-a305.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 132062619FF; Thu, 25 May 2023 01:07:36 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1684976856; a=rsa-sha256; cv=none; b=IY6Zqnls1hB/xz1TTAepewcruJIi9rbmdnMHX0SyFrYUV4N3tMsyvr/xmqZNUi/F7Dl6eQ Kak2MOb381eWYbx2P1LSGogT+J2M2XOlvsca4yMARSvO335/7K12uCQ32OuBN4u/IkekEK S12DEHnUG7RxfNVHv73IT7YBOWmCnqCxk1PiMKmXjvKZCSUQwvXNK1IPAmH9uW+jn0b2kR h6vzTCH0Yidp678hHzPeiRiqQ1qFrLgtEK4GjstkNci08c7gvfkKLHbSrpsqmNy2LsFrHW 19eMfn9d4j4LPOizCha6oLq6UXWLvaCdqe37Iqb9wIQ2RFiyysNMBc84kn+tJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1684976856; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=mpB4Pd94cv3zllvOK96vCCCHB7IDV8kGMvUCTugmDy0=; b=GTynivBVkYSPGzXRLD5FKV6o6iLKrI2/xcPhfHZP2XbesBqMfCF4CQrhSevXk6ahZSpGjC FFiNiGsMuECBBNISPbNwsBrOj+OXfKEZ5/H8rD1Q8uCRFW2NZu0QOOWzZO2i0gdvDgiPO/ NzMgnDeDDFMIaIoXs4TRpAemCg3Q9ptLySsubjuDd/wih1aOHjiekx+iMsCnpgVi+mM3Zk 87xVGAq6Xn/NOl5HalxSG1yCKTAJAhRCf5glX3po4ROYFzQiOjAPly99+uNmDlp4HYadxC tw5gIKxnJK2eNa8edurCq+AWjJFaZQ5LRCBC07OvI5ZRncGTTxZ9gPVA2ZJelA== ARC-Authentication-Results: i=1; rspamd-5cdf8fd7d9-wwc4v; auth=pass smtp.auth=dreamhost smtp.mailfrom=siddhesh@gotplt.org X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Callous-Quick: 359489a8706d2d92_1684976856327_1401348297 X-MC-Loop-Signature: 1684976856327:2958434420 X-MC-Ingress-Time: 1684976856327 Received: from pdx1-sub0-mail-a305.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.109.138.48 (trex/6.8.1); Thu, 25 May 2023 01:07:36 +0000 Received: from [192.168.0.182] (bras-vprn-toroon4834w-lp130-02-142-113-138-85.dsl.bell.ca [142.113.138.85]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a305.dreamhost.com (Postfix) with ESMTPSA id 4QRVK34rjWz1M; Wed, 24 May 2023 18:07:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gotplt.org; s=dreamhost; t=1684976855; bh=uwforvuwMkhJdkqUJxrqm2vMdzBxnSowC2uLMn4sLFY=; h=Date:Subject:To:From:Content-Type:Content-Transfer-Encoding; b=LI1XSsIN1EY6VJQcSiewr8A+51EIT0idPRM6KxF4n33zoL2mXpS1h2BvClpQhQNkF pdlT12LvRRW0w3Q8DnQeXrVmpxWiHCWTlnvnDv8UiaY//cC/MFz5s5lG91WV/fE6NW 4Szg5DsdWITHExxl0jEFtDBcV+KKpQJxg2oLiiMJBxx28SV0l1lDiqn/oEFW3nk3M2 uyx3t4hxI6X+H/pHyZbUw9M4qOaRM19BxazbTo3j362JJ2wFq2Eb3VteIBl6iglnI5 gJLXWuQ1EJjIW9GmP6JRxjy7dla70yE2SZ1OXI5qrsZkqfmtVFFIbaOxYx0HFzzxVd 0o+KwcYNkwcOw== Message-ID: <52b3ae3a-e80c-a320-b07b-a727d28d53f1@gotplt.org> Date: Wed, 24 May 2023 21:07:34 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: [PATCH v4 07/15] tests: fix warn unused result on asprintf calls Content-Language: en-US To: =?UTF-8?B?RnLDqWTDqXJpYyBCw6lyYXQ=?= , libc-alpha@sourceware.org References: <20230428122142.928135-1-fberat@redhat.com> <20230428122142.928135-8-fberat@redhat.com> From: Siddhesh Poyarekar In-Reply-To: <20230428122142.928135-8-fberat@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3037.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 2023-04-28 08:21, Frédéric Bérat wrote: > When enabling _FORTIFY_SOURCE, some functions now lead to warnings when > their result is not checked. > --- > argp/argp-test.c | 8 +++++--- > posix/tst-execl2.c | 8 ++------ > posix/tst-execle2.c | 8 ++------ > posix/tst-execlp2.c | 11 +++-------- > posix/tst-execv2.c | 8 ++------ > posix/tst-execve2.c | 8 ++------ > posix/tst-execvp2.c | 17 ++++------------- > stdio-common/bug5.c | 4 +++- > stdio-common/test-fwrite.c | 4 +++- > stdio-common/tst-fseek.c | 5 ++--- > 10 files changed, 28 insertions(+), 53 deletions(-) > > diff --git a/argp/argp-test.c b/argp/argp-test.c > index c7e20f6235..cd69c81b1a 100644 > --- a/argp/argp-test.c > +++ b/argp/argp-test.c > @@ -25,6 +25,8 @@ > #include > #include > > +#include > + > const char *argp_program_version = "argp-test 1.0"; > > struct argp_option sub_options[] = > @@ -178,12 +180,12 @@ help_filter (int key, const char *text, void *input) > if (key == ARGP_KEY_HELP_POST_DOC && text) > { > time_t now = time (0); > - asprintf (&new_text, text, ctime (&now)); > + new_text = xasprintf (text, ctime (&now)); > } > else if (key == 'f') > /* Show the default for the --foonly option. */ > - asprintf (&new_text, "%s (ZOT defaults to %x)", > - text, params->foonly_default); > + new_text = xasprintf ("%s (ZOT defaults to %x)", > + text, params->foonly_default); > else > new_text = (char *)text; > > diff --git a/posix/tst-execl2.c b/posix/tst-execl2.c > index 5b74959ef8..d2f4453ad8 100644 > --- a/posix/tst-execl2.c > +++ b/posix/tst-execl2.c > @@ -18,12 +18,8 @@ prepare (int argc, char *argv[]) > { > char *buf; > int off; > - asprintf (&buf, "cp %s %n%s-copy", argv[0], &off, argv[0]); > - if (buf == NULL) > - { > - puts ("asprintf failed"); > - exit (1); > - } > + > + buf = xasprintf ("cp %s %n%s-copy", argv[0], &off, argv[0]); > if (system (buf) != 0) > { > puts ("system failed"); > diff --git a/posix/tst-execle2.c b/posix/tst-execle2.c > index 0430b7b573..8e3ad9acb6 100644 > --- a/posix/tst-execle2.c > +++ b/posix/tst-execle2.c > @@ -18,12 +18,8 @@ prepare (int argc, char *argv[]) > { > char *buf; > int off; > - asprintf (&buf, "cp %s %n%s-copy", argv[0], &off, argv[0]); > - if (buf == NULL) > - { > - puts ("asprintf failed"); > - exit (1); > - } > + > + buf = xasprintf ("cp %s %n%s-copy", argv[0], &off, argv[0]); > if (system (buf) != 0) > { > puts ("system failed"); > diff --git a/posix/tst-execlp2.c b/posix/tst-execlp2.c > index 81a723dda4..8f10d4b7f8 100644 > --- a/posix/tst-execlp2.c > +++ b/posix/tst-execlp2.c > @@ -22,12 +22,8 @@ prepare (int argc, char *argv[]) > { > char *buf; > int off; > - asprintf (&buf, "cp %s %n%s-copy", argv[0], &off, argv[0]); > - if (buf == NULL) > - { > - puts ("asprintf failed"); > - exit (1); > - } > + > + buf = xasprintf ("cp %s %n%s-copy", argv[0], &off, argv[0]); > if (system (buf) != 0) > { > puts ("system failed"); > @@ -59,8 +55,7 @@ do_test (void) > return 1; > } > char *path; > - asprintf (&path, "%s:../libio:../elf", bindir); > - if (path == NULL) > + if (asprintf (&path, "%s:../libio:../elf", bindir) < 0 || path == NULL) Couldn't this be: path = xasprintf (...); TEST_VERIFY (path != NULL); Also this is an old style test that uses test-skeleton.c, it needs to be ported over to using support.h. That's probably true for other tests you're touching too (sorry!) > { > puts ("asprintf failed"); > return 1; > diff --git a/posix/tst-execv2.c b/posix/tst-execv2.c > index a5168a269c..5fd6c46c1f 100644 > --- a/posix/tst-execv2.c > +++ b/posix/tst-execv2.c > @@ -18,12 +18,8 @@ prepare (int argc, char *argv[]) > { > char *buf; > int off; > - asprintf (&buf, "cp %s %n%s-copy", argv[0], &off, argv[0]); > - if (buf == NULL) > - { > - puts ("asprintf failed"); > - exit (1); > - } > + > + buf = xasprintf ("cp %s %n%s-copy", argv[0], &off, argv[0]); > if (system (buf) != 0) > { > puts ("system failed"); > diff --git a/posix/tst-execve2.c b/posix/tst-execve2.c > index 1a804e94fd..e0a7c84346 100644 > --- a/posix/tst-execve2.c > +++ b/posix/tst-execve2.c > @@ -18,12 +18,8 @@ prepare (int argc, char *argv[]) > { > char *buf; > int off; > - asprintf (&buf, "cp %s %n%s-copy", argv[0], &off, argv[0]); > - if (buf == NULL) > - { > - puts ("asprintf failed"); > - exit (1); > - } > + > + buf = xasprintf ("cp %s %n%s-copy", argv[0], &off, argv[0]); > if (system (buf) != 0) > { > puts ("system failed"); > diff --git a/posix/tst-execvp2.c b/posix/tst-execvp2.c > index 440dfab438..f6c0cb4d98 100644 > --- a/posix/tst-execvp2.c > +++ b/posix/tst-execvp2.c > @@ -25,12 +25,8 @@ prepare (int argc, char *argv[]) > { > char *buf; > int off; > - asprintf (&buf, "cp %s %n%s-copy", argv[0], &off, argv[0]); > - if (buf == NULL) > - { > - puts ("asprintf failed"); > - exit (1); > - } > + > + buf = xasprintf ("cp %s %n%s-copy", argv[0], &off, argv[0]); > if (system (buf) != 0) > { > puts ("system failed"); > @@ -61,13 +57,8 @@ do_test (void) > puts ("canonicalize_file_name failed"); > return 1; > } > - char *path; > - asprintf (&path, "%s:../libio:../elf", bindir); > - if (path == NULL) > - { > - puts ("asprintf failed"); > - return 1; > - } > + > + char *path = xasprintf ("%s:../libio:../elf", bindir); > > setenv ("PATH", path, 1); > > diff --git a/stdio-common/bug5.c b/stdio-common/bug5.c > index 7bfe9b2b8d..dfa19aed55 100644 > --- a/stdio-common/bug5.c > +++ b/stdio-common/bug5.c > @@ -7,6 +7,8 @@ > #include > #include > > +#include > + > static char buf[8192]; > > int > @@ -60,7 +62,7 @@ main (void) > the perhaps incompatible new shared libraries. */ > unsetenv ("LD_LIBRARY_PATH"); > > - asprintf (&printbuf, "cmp %s %s", inname, outname); > + printbuf = xasprintf ("cmp %s %s", inname, outname); > result = system (printbuf); > remove (inname); > remove (outname); > diff --git a/stdio-common/test-fwrite.c b/stdio-common/test-fwrite.c > index 5677c6da80..7f383921ca 100644 > --- a/stdio-common/test-fwrite.c > +++ b/stdio-common/test-fwrite.c > @@ -1,6 +1,8 @@ > #include > #include > > +#include > + > static int > do_test (void) > { > @@ -57,7 +59,7 @@ do_test (void) > return 1; > } > > - asprintf (&line, "\ > + line = xasprintf ("\ > GDB is free software and you are welcome to distribute copies of it\n\ > under certain conditions; type \"show copying\" to see the conditions.\n\ > There is absolutely no warranty for GDB; type \"show warranty\" for details.\n\ > diff --git a/stdio-common/tst-fseek.c b/stdio-common/tst-fseek.c > index c4ac17cdf4..386dd1dd51 100644 > --- a/stdio-common/tst-fseek.c > +++ b/stdio-common/tst-fseek.c > @@ -25,6 +25,7 @@ > #include > #include > > +#include > > static int > do_test (void) > @@ -44,9 +45,7 @@ do_test (void) > if (tmpdir == NULL || tmpdir[0] == '\0') > tmpdir = "/tmp"; > > - asprintf (&fname, "%s/tst-fseek.XXXXXX", tmpdir); > - if (fname == NULL) > - error (EXIT_FAILURE, errno, "cannot generate name for temporary file"); > + fname = xasprintf ("%s/tst-fseek.XXXXXX", tmpdir); > > /* Create a temporary file. */ > fd = mkstemp (fname);