From patchwork Thu Jun 1 14:27:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Berat X-Patchwork-Id: 1789100 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=vxuM4pHR; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QX7mq0Jtrz20QB for ; Fri, 2 Jun 2023 00:29:15 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1106838558BE for ; Thu, 1 Jun 2023 14:29:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1106838558BE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1685629753; bh=+Rwdi6HclO/6EnKhuzxw9VKw3+PM7PA/BI0yEU3zzdU=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=vxuM4pHRQJxkBlRyU3eWw5FvM7rq9KmbY4DfNXBJAR96N3GMUrWV7/Nkb8TJDU/bx fYF5DSlOuZScbcf8eaeMKlA5isY6CmKBfvXcI0VzVLHnXM0UD9GfMGQH/E18wKY6d/ H7F7cgYxnLgpwObHB/fkBZLik0zzHwsIkSyiSJeA= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 6937D3857438 for ; Thu, 1 Jun 2023 14:28:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6937D3857438 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-516-vJiNLnihPNabs8riUC02uQ-1; Thu, 01 Jun 2023 10:28:09 -0400 X-MC-Unique: vJiNLnihPNabs8riUC02uQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6196B80120A; Thu, 1 Jun 2023 14:28:08 +0000 (UTC) Received: from Nymeria-redhat.redhat.com (unknown [10.39.193.180]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B97299E63; Thu, 1 Jun 2023 14:28:06 +0000 (UTC) To: libc-alpha@sourceware.org Cc: siddhesh@gotplt.org, fberat@redhat.com Subject: [PATCH v5 04/12] tests: fix warn unused result on asprintf calls Date: Thu, 1 Jun 2023 16:27:45 +0200 Message-Id: <20230601142747.104444-4-fberat@redhat.com> In-Reply-To: <20230418121130.844302-2-fberat@redhat.com> References: <20230601142747.104444-1-fberat@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIM_INVALID, DKIM_SIGNED, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, 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 X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: =?utf-8?q?Fr=C3=A9d=C3=A9ric_B=C3=A9rat_via_Libc-alpha?= From: Frederic Berat Reply-To: =?utf-8?b?RnLDqWTDqXJpYyBCw6lyYXQ=?= Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" When enabling _FORTIFY_SOURCE, some functions now lead to warnings when their result is not checked. --- Changes since v4: - Properly use xasprintf in all cases in posix/tst-execlp2.c argp/argp-test.c | 8 +++++--- posix/tst-execl2.c | 8 ++------ posix/tst-execle2.c | 8 ++------ posix/tst-execlp2.c | 10 +++------- 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(+), 52 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..b42037babd 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,7 +55,7 @@ do_test (void) return 1; } char *path; - asprintf (&path, "%s:../libio:../elf", bindir); + path = xasprintf ("%s:../libio:../elf", bindir); if (path == NULL) { puts ("asprintf failed"); 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);