[PATCH] tests/xs: Check asprintf result

Jason Andryuk posted 1 patch 2 years, 9 months ago
Failed in applying to current master (apply log)
tools/tests/xenstore/xs-test.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
[PATCH] tests/xs: Check asprintf result
Posted by Jason Andryuk 2 years, 9 months ago
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(-)

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);
-- 
2.30.2


Re: [PATCH] tests/xs: Check asprintf result
Posted by Ian Jackson 2 years, 9 months ago
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.

Re: [PATCH] tests/xs: Check asprintf result
Posted by Jason Andryuk 2 years, 9 months ago
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

Re: [PATCH] tests/xs: Check asprintf result
Posted by Andrew Cooper 2 years, 9 months ago
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


Re: [PATCH] tests/xs: Check asprintf result
Posted by Ian Jackson 2 years, 9 months ago
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.