Skip to contentSkip to conversation

tests/xs: Check asprintf result

PATCH In review Jason Andryuk 3 participants 5 messages Jul 18, 2021 – Jul 20, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tests/xs: Check asprintf result

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.

---
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(-)
tools/tests/xenstore/xs-test.c +11 -2
index c4c99c0661..f42c1cfe66 100644
@@ -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);
Signature · 1 line
2.30.2
#1 lore raw

Jason Andryuk writes ("[PATCH] tests/xs: Check asprintf result"):

Quoted 1 line

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.

#2 lore raw
Quoted 4 lines · Ian Jackson

Jason Andryuk writes ("[PATCH] tests/xs: Check asprintf result"):

Quoted 1 line

Compiling xs-test.c on Ubuntu 21.04 fails with:

Quoted 8 lines

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

#3 lore raw
In reply to Ian Jackson
Quoted 10 lines · Ian Jackson

Jason Andryuk writes ("[PATCH] tests/xs: Check asprintf result"):

Quoted 1 line

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

#4 lore raw

Andrew Cooper writes ("Re: [PATCH] tests/xs: Check asprintf result"):

Quoted 5 lines · Ian Jackson
Quoted 2 lines

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.