public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Frederic Berat <fberat@redhat.com>
To: Siddhesh Poyarekar <siddhesh@gotplt.org>
Cc: libc-alpha@sourceware.org
Subject: Re: [PATCH v4 07/15] tests: fix warn unused result on asprintf calls
Date: Wed, 31 May 2023 16:36:41 +0200	[thread overview]
Message-ID: <CAObJKZpomwt67TeRrPBMmZ7z_cqvNo+WNmPG9AxfwjB=zOfU2w@mail.gmail.com> (raw)
In-Reply-To: <52b3ae3a-e80c-a320-b07b-a727d28d53f1@gotplt.org>

On Thu, May 25, 2023 at 3:07 AM Siddhesh Poyarekar <siddhesh@gotplt.org> wrote:
>
> 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 <string.h>
> >   #include <argp.h>
> >
> > +#include <support/support.h>
> > +
> >   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!)
>

Although I agree the test needs porting, I'd prefer to keep the scope
of the change focused on the wur fix if you don´t mind.
The porting may be done in a separate patchset.

> >       {
> >         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 <stdlib.h>
> >   #include <unistd.h>
> >
> > +#include <support/support.h>
> > +
> >   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 <stdio.h>
> >   #include <string.h>
> >
> > +#include <support/support.h>
> > +
> >   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 <time.h>
> >   #include <sys/stat.h>
> >
> > +#include <support/support.h>
> >
> >   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);
>


  reply	other threads:[~2023-05-31 14:36 UTC|newest]

Thread overview: 109+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-18 12:11 [PATCH 0/8] Fix warn unused result Frédéric Bérat
2023-04-18 12:11 ` [PATCH 1/8] tests: fix " Frédéric Bérat
2023-04-18 12:23   ` Siddhesh Poyarekar
2023-04-28 12:21   ` [PATCH v4 07/15] tests: fix warn unused result on asprintf calls Frédéric Bérat
2023-05-25  1:07     ` Siddhesh Poyarekar
2023-05-31 14:36       ` Frederic Berat [this message]
2023-04-28 12:21   ` [PATCH v4 08/15] tests: replace write by xwrite Frédéric Bérat
2023-05-25  1:16     ` Siddhesh Poyarekar
2023-06-01 16:39       ` Siddhesh Poyarekar
2023-04-28 12:21   ` [PATCH v4 09/15] tests: replace read by xread Frédéric Bérat
2023-04-28 12:21   ` [PATCH v4 10/15] tests: replace system by xsystem Frédéric Bérat
2023-05-25  1:22     ` Siddhesh Poyarekar
2023-04-28 12:21   ` [PATCH v4 11/15] tests: replace fread by xfread Frédéric Bérat
2023-04-28 12:21   ` [PATCH v4 12/15] tests: replace ftruncate by xftruncate Frédéric Bérat
2023-05-25  1:25     ` Siddhesh Poyarekar
2023-06-01 16:42       ` Siddhesh Poyarekar
2023-04-28 12:21   ` [PATCH v4 13/15] tests: replace fgets by xfgets Frédéric Bérat
2023-04-28 12:21   ` [PATCH v4 14/15] tests: Replace various function calls with their x variant Frédéric Bérat
2023-05-25  1:29     ` Siddhesh Poyarekar
2023-05-25 16:10       ` Frederic Berat
2023-04-28 12:21   ` [PATCH v4 15/15] tests: fix warn unused results Frédéric Bérat
2023-05-25  1:35     ` Siddhesh Poyarekar
2023-06-01 14:27   ` [PATCH v5 04/12] tests: fix warn unused result on asprintf calls Frédéric Bérat
2023-06-01 16:52     ` Siddhesh Poyarekar
2023-06-01 14:27   ` [PATCH v5 07/12] tests: replace system by xsystem Frédéric Bérat
2023-06-01 16:56     ` Siddhesh Poyarekar
2023-06-01 14:27   ` [PATCH v5 12/12] tests: fix warn unused results Frédéric Bérat
2023-06-01 16:57     ` Siddhesh Poyarekar
2023-04-18 12:11 ` [PATCH 2/8] catgets/gencat.c: fix warn unused result Frédéric Bérat
2023-04-18 12:36   ` Siddhesh Poyarekar
2023-04-28 12:21   ` [PATCH v4 01/15] " Frédéric Bérat
2023-05-24 22:47     ` Siddhesh Poyarekar
2023-06-01 14:27   ` [PATCH v5 01/12] " Frédéric Bérat
2023-06-01 16:47     ` Siddhesh Poyarekar
2023-04-18 12:11 ` [PATCH 3/8] inet/rcmd.c: " Frédéric Bérat
2023-04-18 12:37   ` Siddhesh Poyarekar
2023-04-18 13:40   ` Andreas Schwab
2023-04-18 13:50     ` Siddhesh Poyarekar
2023-04-18 12:11 ` [PATCH 4/8] locale/programs/locarchive.c: " Frédéric Bérat
2023-04-18 12:43   ` Siddhesh Poyarekar
2023-04-28 12:21   ` [PATCH v4 02/15] " Frédéric Bérat
2023-05-24 22:49     ` Siddhesh Poyarekar
2023-06-01 14:27   ` [PATCH v5 02/12] malloc/{memusage.c,memusagestat.c}: " Frédéric Bérat
2023-06-01 16:49     ` Siddhesh Poyarekar
2023-04-18 12:11 ` [PATCH 5/8] " Frédéric Bérat
2023-04-18 12:47   ` [PATCH 5/8] malloc/{memusage.c, memusagestat.c}: " Siddhesh Poyarekar
2023-04-28 12:21   ` [PATCH v4 03/15] malloc/{memusage.c,memusagestat.c}: " Frédéric Bérat
2023-05-25  0:50     ` Siddhesh Poyarekar
2023-06-01 15:55       ` [PATCH] Move {read,write}_all functions to a dedicated header Frédéric Bérat
2023-06-01 17:07         ` Siddhesh Poyarekar
2023-06-02  6:10           ` Frederic Berat
2023-06-02 10:01             ` Siddhesh Poyarekar
2023-04-18 12:11 ` [PATCH 6/8] nptl_db/thread_dbP.h: fix warn unused result Frédéric Bérat
2023-04-18 12:49   ` Siddhesh Poyarekar
2023-04-18 12:51     ` Siddhesh Poyarekar
2023-04-28 12:21   ` [PATCH v4 04/15] " Frédéric Bérat
2023-05-25  0:51     ` Siddhesh Poyarekar
2023-05-25  1:52       ` Siddhesh Poyarekar
2023-06-01 14:27   ` [PATCH v5 03/12] " Frédéric Bérat
2023-06-01 16:49     ` Siddhesh Poyarekar
2023-04-18 12:11 ` [PATCH 7/8] sunrpc/netname.c: " Frédéric Bérat
2023-04-18 12:51   ` Siddhesh Poyarekar
2023-04-28 12:21   ` [PATCH v4 05/15] " Frédéric Bérat
2023-05-25  0:53     ` Siddhesh Poyarekar
2023-04-18 12:11 ` [PATCH 8/8] sysdeps/pthread/eintr.c: " Frédéric Bérat
2023-04-18 12:54   ` Siddhesh Poyarekar
2023-04-28 12:21   ` [PATCH v4 06/15] " Frédéric Bérat
2023-05-25  0:59     ` Siddhesh Poyarekar
2023-04-28 12:21 ` [PATCH v4 00/15] Fix " Frédéric Bérat
2023-05-25  1:53   ` Siddhesh Poyarekar
2023-06-02 15:28 ` [PATCH v6 0/7] " Frédéric Bérat
2023-06-02 15:28   ` [PATCH v6 1/7] tests: fix warn unused result on asprintf calls Frédéric Bérat
2023-06-06  6:18     ` Siddhesh Poyarekar
2023-06-02 15:28   ` [PATCH v6 2/7] tests: replace read by xread Frédéric Bérat
2023-06-06  6:21     ` Siddhesh Poyarekar
2023-06-06  8:00       ` Frederic Berat
2023-06-12 14:22         ` Siddhesh Poyarekar
2023-06-07 19:04     ` Frederic Berat
2023-06-02 15:28   ` [PATCH v6 3/7] tests: replace system by xsystem Frédéric Bérat
2023-06-06 12:17     ` Siddhesh Poyarekar
2023-06-02 15:28   ` [PATCH v6 4/7] tests: replace fread by xfread Frédéric Bérat
2023-06-06 12:18     ` Siddhesh Poyarekar
2023-06-07 19:03     ` Frederic Berat
2023-06-02 15:28   ` [PATCH v6 5/7] tests: replace fgets by xfgets Frédéric Bérat
2023-06-06 12:20     ` Siddhesh Poyarekar
2023-06-08  5:50     ` Maxim Kuvyrkov
2023-06-08  6:57       ` Frederic Berat
2023-06-02 15:28   ` [PATCH v6 6/7] tests: Replace various function calls with their x variant Frédéric Bérat
2023-06-06 12:20     ` Siddhesh Poyarekar
2023-06-02 15:28   ` [PATCH v6 7/7] Move {read,write}_all functions to a dedicated header Frédéric Bérat
2023-06-06 12:21     ` Siddhesh Poyarekar
2023-06-12 15:18 ` [PATCH v7 0/4] Fix warn unused result Frédéric Bérat
2023-06-12 15:18   ` [PATCH v7 1/4] tests: replace read by xread Frédéric Bérat
2023-06-12 16:57     ` Joseph Myers
2023-06-13 14:22       ` Frederic Berat
2023-06-14  8:52     ` [PATCH v8 1/2] " Frédéric Bérat
2023-06-14 11:51       ` Siddhesh Poyarekar
2023-06-12 15:18   ` [PATCH v7 2/4] tests: replace system by xsystem Frédéric Bérat
2023-06-13 14:10     ` Siddhesh Poyarekar
2023-06-13 14:13     ` Adhemerval Zanella Netto
2023-06-13 14:16       ` Siddhesh Poyarekar
2023-06-14  8:52     ` [PATCH 2/2] " Frédéric Bérat
2023-06-14 11:53       ` Siddhesh Poyarekar
2023-06-12 15:18   ` [PATCH v7 3/4] tests: replace fread by xfread Frédéric Bérat
2023-06-13 23:57     ` Siddhesh Poyarekar
2023-06-12 15:18   ` [PATCH v7 4/4] tests: replace fgets by xfgets Frédéric Bérat
2023-06-13 12:23     ` Siddhesh Poyarekar
2023-06-13 18:25       ` Joseph Myers
2023-06-13 23:56         ` Siddhesh Poyarekar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAObJKZpomwt67TeRrPBMmZ7z_cqvNo+WNmPG9AxfwjB=zOfU2w@mail.gmail.com' \
    --to=fberat@redhat.com \
    --cc=libc-alpha@sourceware.org \
    --cc=siddhesh@gotplt.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).