]> xenbits.xensource.com Git - people/dariof/xen.git/commitdiff
xen-detect: handle asprintf error
authorWei Liu <wei.liu2@citrix.com>
Wed, 21 Jun 2017 14:41:52 +0000 (15:41 +0100)
committerWei Liu <wei.liu2@citrix.com>
Fri, 23 Jun 2017 15:08:40 +0000 (16:08 +0100)
Otherwise gcc with -Wunused will complain the return value is not
used.

Reported-by: Olaf Hering <olaf@aepfle.de>
Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
tools/misc/xen-detect.c

index a62747d3166238e37fdc81e38343c436ee7ed9f0..fd187a4be6c51d36ede4f3e65bf232d7191f1548 100644 (file)
@@ -90,8 +90,15 @@ static int check_for_xen(int pv_context)
  found:
     cpuid(base + 1, regs, pv_context);
     if ( regs[0] )
-        asprintf(&ver, "V%u.%u",
-                 (uint16_t)(regs[0] >> 16), (uint16_t)regs[0]);
+    {
+        int r = asprintf(&ver, "V%u.%u", (uint16_t)(regs[0] >> 16),
+                         (uint16_t)regs[0]);
+        if ( r < 0 )
+        {
+            perror("asprintf failed\n");
+            exit(EXIT_FAILURE);
+        }
+    }
     return regs[0];
 }
 
@@ -193,8 +200,14 @@ static enum guest_type check_sysfs(void)
     if ( tmp )
         tmp[strlen(tmp) - 1] = 0;
     if ( str && tmp )
-        asprintf(&ver, "V%s.%s", str, tmp);
-    else
+    {
+        int r = asprintf(&ver, "V%s.%s", str, tmp);
+        if ( r < 0 )
+        {
+            perror("asprintf failed\n");
+            exit(EXIT_FAILURE);
+        }
+    } else
         ver = strdup("unknown version");
     free(tmp);