From 8c4f69d711481a18c70cb9a6c0a5367604894320 Mon Sep 17 00:00:00 2001 From: Frédéric Bérat Date: Fri, 2 Jun 2023 17:28:06 +0200 Subject: tests: fix warn unused result on asprintf calls When enabling _FORTIFY_SOURCE, some functions now lead to warnings when their result is not checked. Reviewed-by: Siddhesh Poyarekar --- posix/tst-execl2.c | 8 ++------ posix/tst-execle2.c | 8 ++------ posix/tst-execlp2.c | 17 ++++------------- posix/tst-execv2.c | 8 ++------ posix/tst-execve2.c | 8 ++------ posix/tst-execvp2.c | 17 ++++------------- 6 files changed, 16 insertions(+), 50 deletions(-) (limited to 'posix') 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..4c3afb8539 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"); @@ -58,13 +54,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/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); -- cgit 1.4.1