Skip to contentSkip to conversation

error: passing a negative value to an os_errno is wrong

PATCH Superseded SeokYeon Hwang 3 participants 4 messages Nov 7, 2014 – Nov 10, 2014

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 error: passing a negative value to an os_errno is wrong

Added 'assert(os_errno > 0)' in 'error_set_errno()'. Fixed errno since it passes wrong value to 'error_set_errno()'.

---
 hw/pci/pcie.c | 2 +-
 util/error.c  | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
hw/pci/pcie.c +1 -1
index 58455bd..2902f7d 100644
@@ -229,7 +229,7 @@ static void pcie_cap_slot_hotplug_common(PCIDevice *hotplug_dev,
         /* the slot is electromechanically locked.
          * This error is propagated up to qdev and then to HMP/QMP.
          */
-        error_setg_errno(errp, -EBUSY, "slot is electromechanically locked");
+        error_setg_errno(errp, EBUSY, "slot is electromechanically locked");
     }
 }
 
util/error.c +1 -0
index 2ace0d8..4ce22cc 100644
@@ -62,6 +62,7 @@ void error_set_errno(Error **errp, int os_errno, ErrorClass err_class,
         return;
     }
     assert(*errp == NULL);
+    assert(os_errno > 0);
 
     err = g_malloc0(sizeof(*err));
 
Signature · 1 line
2.1.0
#1 lore raw
Quoted 27 lines · SeokYeon Hwang

Added 'assert(os_errno > 0)' in 'error_set_errno()'. Fixed errno since it passes wrong value to 'error_set_errno()'.

---
 hw/pci/pcie.c | 2 +-
 util/error.c  | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
hw/pci/pcie.c +1 -1
index 58455bd..2902f7d 100644
@@ -229,7 +229,7 @@ static void pcie_cap_slot_hotplug_common(PCIDevice *hotplug_dev,
         /* the slot is electromechanically locked.
          * This error is propagated up to qdev and then to HMP/QMP.
          */
-        error_setg_errno(errp, -EBUSY, "slot is electromechanically locked");
+        error_setg_errno(errp, EBUSY, "slot is electromechanically locked");
     }
 }
 
util/error.c +0 -0
index 2ace0d8..4ce22cc 100644

util/error.c void error_set_errno(Error **errp, int os_errno, ErrorClass err_class, · line 65

Quoted 4 lines
util/error.c +1 -0
@@ -62,6 +62,7 @@ void error_set_errno(Error **errp, int os_errno, ErrorClass err_class,
         return;
     }
     assert(*errp == NULL);
+    assert(os_errno > 0);

strerror(0) will return string 'Success', do we need to reserve zero here?

      assert(os_errno >= 0);
Quoted 6 lines
util/error.c +0 -0
     err = g_malloc0(sizeof(*err));
 
Signature · 1 line
2.1.0
Signature · 1 line
			Amos.
#2 lore raw
Quoted 35 lines · Amos Kong
Quoted 27 lines · SeokYeon Hwang

Added 'assert(os_errno > 0)' in 'error_set_errno()'. Fixed errno since it passes wrong value to 'error_set_errno()'.

---
 hw/pci/pcie.c | 2 +-
 util/error.c  | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
hw/pci/pcie.c +1 -1
index 58455bd..2902f7d 100644
@@ -229,7 +229,7 @@ static void pcie_cap_slot_hotplug_common(PCIDevice *hotplug_dev,
         /* the slot is electromechanically locked.
          * This error is propagated up to qdev and then to HMP/QMP.
          */
-        error_setg_errno(errp, -EBUSY, "slot is electromechanically locked");
+        error_setg_errno(errp, EBUSY, "slot is electromechanically locked");
     }
 }
 
util/error.c +0 -0
index 2ace0d8..4ce22cc 100644

util/error.c void error_set_errno(Error **errp, int os_errno, ErrorClass err_class, · line 65

Quoted 4 lines
util/error.c +1 -0
@@ -62,6 +62,7 @@ void error_set_errno(Error **errp, int os_errno, ErrorClass err_class,
         return;
     }
     assert(*errp == NULL);
+    assert(os_errno > 0);

strerror(0) will return string 'Success', do we need to reserve zero here?

Quoted 1 line
      assert(os_errno >= 0);

Yes, because...

Quoted 2 lines

util/error.c void error_set_errno(Error **errp, int os_errno, ErrorClass err_class, · line 68

Quoted 2 lines
util/error.c +0 -0
     err = g_malloc0(sizeof(*err));
 
        va_start(ap, fmt);
        msg1 = g_strdup_vprintf(fmt, ap);
--->    if (os_errno != 0) {
            err->msg = g_strdup_printf("%s: %s", msg1, strerror(os_errno));
            g_free(msg1);
        } else {
            err->msg = msg1;
        }

Please fix.

#3 lore raw
Quoted 53 lines

-----Original Message-----
From: Markus Armbruster [mailto:[email protected]]
Sent: Friday, November 07, 2014 4:41 PM
To: Amos Kong
Cc: SeokYeon Hwang; [email protected]; [email protected]; qemu- [email protected]
Subject: Re: [Qemu-devel] [PATCH v2] error: passing a negative value to an os_errno is wrong

Quoted 10 lines · Amos Kong
Quoted 9 lines · SeokYeon Hwang

Added 'assert(os_errno > 0)' in 'error_set_errno()'. Fixed errno since it passes wrong value to 'error_set_errno()'.

---
 hw/pci/pcie.c | 2 +-
 util/error.c  | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
Quoted 5 lines

hw/pci/pcie.c static void pcie_cap_slot_hotplug_common(PCIDevice

Quoted 5 lines
hw/pci/pcie.c index 58455bd..2902f7d renamed from hw/pci/pcie.c +0 -0

100644

hw/pci/pcie.c +0 -0
@@ -229,7 +229,7 @@ static void pcie_cap_slot_hotplug_common(PCIDevice

*hotplug_dev,

Quoted 4 lines

hw/pci/pcie.c static void pcie_cap_slot_hotplug_common(PCIDevice *hotplug_dev,

Quoted 4 lines
hw/pci/pcie.c +0 -1
         /* the slot is electromechanically locked.
          * This error is propagated up to qdev and then to HMP/QMP.
          */
-        error_setg_errno(errp, -EBUSY, "slot is electromechanically

locked");

Quoted 10 lines

util/error.c void error_set_errno(Error **errp, int os_errno,

Quoted 10 lines
hw/pci/pcie.c +2 -0
+        error_setg_errno(errp, EBUSY, "slot is electromechanically
+ locked");
     }
 }
util/error.c index 2ace0d8..4ce22cc renamed from util/error.c +0 -0

100644

util/error.c +0 -0
@@ -62,6 +62,7 @@ void error_set_errno(Error **errp, int os_errno,

ErrorClass err_class,

Quoted 6 lines

util/error.c void error_set_errno(Error **errp, int os_errno, ErrorClass err_class, · line 65

Quoted 4 lines
util/error.c +1 -0
         return;
     }
     assert(*errp == NULL);
+    assert(os_errno > 0);

strerror(0) will return string 'Success', do we need to reserve zero

here?

Quoted 2 lines
      assert(os_errno >= 0);
Quoted 8 lines

Yes, because...

Quoted 2 lines

util/error.c void error_set_errno(Error **errp, int os_errno, ErrorClass err_class, · line 68

Quoted 2 lines
util/error.c +0 -0
     err = g_malloc0(sizeof(*err));
 
        va_start(ap, fmt);
        msg1 = g_strdup_vprintf(fmt, ap);
--->    if (os_errno != 0) {
            err->msg = g_strdup_printf("%s: %s", msg1,

strerror(os_errno));

Quoted 6 lines
            g_free(msg1);
        } else {
            err->msg = msg1;
        }

Please fix.

You're right. I posted patch v3.
Thank you for your advice.