Skip to contentSkip to conversation

block/xen_disk: Convert atoi use to qemu_strtol to allow error checking

PATCH In review Nia Alarie 1 participant 2 messages Mar 16, 2018

lore
Share & tools
lore

Nia Alarie

author
#0 lore raw

PATCH 1/1 block/xen_disk: Convert atoi use to qemu_strtol to allow error checking

---
 hw/block/xen_disk.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
hw/block/xen_disk.c +5 -1
index f74fcd42d1..a9ec0ad6eb 100644
@@ -32,6 +32,7 @@
 #include "qapi/error.h"
 #include "qapi/qmp/qdict.h"
 #include "qapi/qmp/qstring.h"
+#include "qemu/cutils.h"
 #include "trace.h"
 
 /* ------------------------------------------------------------- */
@@ -1010,7 +1011,10 @@ static int blk_init(struct XenDevice *xendev)
         blkdev->devtype = xenstore_read_be_str(&blkdev->xendev, "device-type");
     }
     directiosafe = xenstore_read_be_str(&blkdev->xendev, "direct-io-safe");
-    blkdev->directiosafe = (directiosafe && atoi(directiosafe));
+
+    if (directiosafe && qemu_strtoi(directiosafe, NULL, 10, &blkdev->directiosafe)) {
+        goto out_error;
+    }
 
     /* do we have all we need? */
     if (blkdev->params == NULL ||
Signature · 1 line
2.16.2
author
#1 lore raw
Quoted 30 lines · Nia Alarie
---
 hw/block/xen_disk.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
hw/block/xen_disk.c +5 -2
index f74fcd42d1..a9ec0ad6eb 100644
@@ -32,6 +32,7 @@
 #include "qapi/error.h"
 #include "qapi/qmp/qdict.h"
 #include "qapi/qmp/qstring.h"
+#include "qemu/cutils.h"
 #include "trace.h"
 
 /* ------------------------------------------------------------- */
@@ -1010,7 +1011,10 @@ static int blk_init(struct XenDevice *xendev)
         blkdev->devtype = xenstore_read_be_str(&blkdev->xendev, "device-type");
     }
     directiosafe = xenstore_read_be_str(&blkdev->xendev, "direct-io-safe");
-    blkdev->directiosafe = (directiosafe && atoi(directiosafe));
+
+    if (directiosafe && qemu_strtoi(directiosafe, NULL, 10, &blkdev->directiosafe)) {
+        goto out_error;
+    }
 
     /* do we have all we need? */
     if (blkdev->params == NULL ||
--
Quoted 2 lines

2.16.2

I've just realised that this patch is slightly wrong and doesn't match the original code exactly. Please disregard.