[libvirt] [PATCHv3 1/2] virsh: Reject negative numbers in vshCommandOptUInt

Peter Krempa pkrempa at redhat.com
Thu May 29 11:54:51 UTC 2014


Use virStrToLong_uip instead of virStrToLong_ui to reject negative
numbers in the helper. None of the callers expects the wraparound
"feature" for negative numbers.

Also be explicit about the new semantics in the function docs.
---
 tools/virsh.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index 15f3025..483dc04 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -1501,7 +1501,7 @@ vshCommandOptInt(const vshCmd *cmd, const char *name, int *value)
  * @name option name
  * @value result
  *
- * Convert option to unsigned int
+ * Convert option to unsigned int, reject negative numbers
  * See vshCommandOptInt()
  */
 int
@@ -1514,7 +1514,7 @@ vshCommandOptUInt(const vshCmd *cmd, const char *name, unsigned int *value)
     if (ret <= 0)
         return ret;

-    if (virStrToLong_ui(arg->data, NULL, 10, value) < 0)
+    if (virStrToLong_uip(arg->data, NULL, 10, value) < 0)
         return -1;
     return 1;
 }
-- 
1.9.3




More information about the libvir-list mailing list