error: passing a negative value to an os_errno is wrong
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
@@ -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
@@ -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
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()'.Signed-off-by SeokYeon Hwang <[email protected]>--- hw/pci/pcie.c | 2 +- util/error.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)hw/pci/pcie.c +1
-1@@ -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
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
-0err =g_malloc0 (sizeof (*err));Signature · 1 line
2.1.0
Signature · 1 line
Amos.
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()'.Signed-off-by SeokYeon Hwang <[email protected]>--- hw/pci/pcie.c | 2 +- util/error.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)hw/pci/pcie.c +1
-1@@ -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
-0util/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
-0err =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.
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 anos_errnois wrongQuoted 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()'.Signed-off-by SeokYeon Hwang <[email protected]>--- 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
-0100644
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 electromechanicallylocked");
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
-0100644
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
-0return ; }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
-0err =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.