diff mbox series

tests/xs: Check asprintf result

Message ID 20210718135633.28675-1-jandryuk@gmail.com (mailing list archive)
State New
Headers show
Series tests/xs: Check asprintf result | expand

Commit Message

Jason Andryuk July 18, 2021, 1:56 p.m. UTC
Compiling xs-test.c on Ubuntu 21.04 fails with:

xs-test.c: In function ‘main’:
xs-test.c:486:5: error: ignoring return value of ‘asprintf’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result]
  486 |     asprintf(&path, "%s/%u", TEST_PATH, getpid());
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Check the asprintf return and exit if it failed.

Signed-off-by: Jason Andryuk <jandryuk@gmail.com>
---
Using exit(2) since it is used for the xs_open failure.
---
 tools/tests/xenstore/xs-test.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

Comments

Ian Jackson July 20, 2021, 2:31 p.m. UTC | #1
Jason Andryuk writes ("[PATCH] tests/xs: Check asprintf result"):
> Compiling xs-test.c on Ubuntu 21.04 fails with:

Thanks.  However, your patch doesn't apply to staging; the files have
been reorganised AFAICT.  Also, I think

  93c9edbef51b31056f93a37a778326c90a83158c
  tests/xenstore: Rework Makefile

fixed this (with slightly different style, and despite not mentioning
this change in the commit message)

Ian.
Jason Andryuk July 20, 2021, 2:41 p.m. UTC | #2
On Tue, Jul 20, 2021 at 10:31 AM Ian Jackson <iwj@xenproject.org> wrote:
>
> Jason Andryuk writes ("[PATCH] tests/xs: Check asprintf result"):
> > Compiling xs-test.c on Ubuntu 21.04 fails with:
>
> Thanks.  However, your patch doesn't apply to staging; the files have
> been reorganised AFAICT.  Also, I think
>
>   93c9edbef51b31056f93a37a778326c90a83158c
>   tests/xenstore: Rework Makefile
>
> fixed this (with slightly different style, and despite not mentioning
> this change in the commit message)

Yes, that looks like it fixed it.

Sorry, I was working off a stale branch, so I didn't realize this was fixed.

Regards,
Jason
Andrew Cooper July 20, 2021, 3:40 p.m. UTC | #3
On 20/07/2021 15:31, Ian Jackson wrote:
> Jason Andryuk writes ("[PATCH] tests/xs: Check asprintf result"):
>> Compiling xs-test.c on Ubuntu 21.04 fails with:
> Thanks.  However, your patch doesn't apply to staging; the files have
> been reorganised AFAICT.  Also, I think
>
>   93c9edbef51b31056f93a37a778326c90a83158c
>   tests/xenstore: Rework Makefile
>
> fixed this (with slightly different style, and despite not mentioning
> this change in the commit message)

?  Literally half of the commit message pertains to this failure.

~Andrew
Ian Jackson July 20, 2021, 3:59 p.m. UTC | #4
Andrew Cooper writes ("Re: [PATCH] tests/xs: Check asprintf result"):
> On 20/07/2021 15:31, Ian Jackson wrote:
> > fixed this (with slightly different style, and despite not mentioning
> > this change in the commit message)
> 
> ?  Literally half of the commit message pertains to this failure.

Sorry, I meant the title, which talks only about Makefile stuff.

Ian.
diff mbox series

Patch

diff --git a/tools/tests/xenstore/xs-test.c b/tools/tests/xenstore/xs-test.c
index c4c99c0661..f42c1cfe66 100644
--- a/tools/tests/xenstore/xs-test.c
+++ b/tools/tests/xenstore/xs-test.c
@@ -483,11 +483,20 @@  int main(int argc, char *argv[])
         return 0;
     }
 
-    asprintf(&path, "%s/%u", TEST_PATH, getpid());
+    ret = asprintf(&path, "%s/%u", TEST_PATH, getpid());
+    if (ret == -1) {
+        perror("asprintf");
+        exit(2);
+    }
+
     for ( t = 0; t < WRITE_BUFFERS_N; t++ )
     {
         memset(write_buffers[t], 'a' + t, WRITE_BUFFERS_SIZE);
-        asprintf(&paths[t], "%s/%c", path, 'a' + t);
+        ret = asprintf(&paths[t], "%s/%c", path, 'a' + t);
+        if (ret == -1) {
+            perror("asprintf");
+            exit(2);
+        }
     }
 
     xsh = xs_open(0);