Skip to contentSkip to conversation

xen-detect: handle asprintf error

PATCH In review Wei Liu 2 participants 2 messages Jun 21, 2017 – Jun 23, 2017

lore
Share & tools
lore

Wei Liu

author
#0 lore raw

PATCH 1/1 xen-detect: handle asprintf error

Otherwise gcc with -Wunused will complain the return value is not used.

---
Cc: Ian Jackson <[email protected]>
Cc: Olaf Hering <[email protected]>
Cc: Juergen Gross <[email protected]>

---
 tools/misc/xen-detect.c | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)
tools/misc/xen-detect.c +17 -4
index a62747d316..fd187a4be6 100644
@@ -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);
 
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel