Patchwork [v3,1/2] cutils:change strtosz_suffix_unit function

login
register
mail settings
Submitter liguang
Date Dec. 17, 2012, 1:49 a.m.
Message ID <1355708963-17675-1-git-send-email-lig.fnst@cn.fujitsu.com>
Download mbox | patch
Permalink /patch/206767/
State New
Headers show

Comments

liguang - Dec. 17, 2012, 1:49 a.m.
if value to be translated is larger than INT64_MAX,
this function will not be convenient for caller to
be aware of it, so change a little for this.

Signed-off-by: liguang <lig.fnst@cn.fujitsu.com>
---
 cutils.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
Stefan Hajnoczi - Dec. 18, 2012, 2:25 p.m.
On Mon, Dec 17, 2012 at 09:49:22AM +0800, liguang wrote:
> if value to be translated is larger than INT64_MAX,
> this function will not be convenient for caller to
> be aware of it, so change a little for this.
> 
> Signed-off-by: liguang <lig.fnst@cn.fujitsu.com>
> ---
>  cutils.c |    6 ++++--
>  1 files changed, 4 insertions(+), 2 deletions(-)

Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block

Please follow the "<component>: <summary>" convention for commit
messages with a space after the ':'.

There was a conflict with a9300911 that was easy to resolve.

Stefan

Patch

diff --git a/cutils.c b/cutils.c
index 4f0692f..0433e05 100644
--- a/cutils.c
+++ b/cutils.c
@@ -214,12 +214,13 @@  static int64_t suffix_mul(char suffix, int64_t unit)
 /*
  * Convert string to bytes, allowing either B/b for bytes, K/k for KB,
  * M/m for MB, G/g for GB or T/t for TB. End pointer will be returned
- * in *end, if not NULL. Return -1 on error.
+ * in *end, if not NULL. Return -ERANGE on overflow, Return -EINVAL on
+ * other error.
  */
 int64_t strtosz_suffix_unit(const char *nptr, char **end,
                             const char default_suffix, int64_t unit)
 {
-    int64_t retval = -1;
+    int64_t retval = -EINVAL;
     char *endptr;
     unsigned char c;
     int mul_required = 0;
@@ -246,6 +247,7 @@  int64_t strtosz_suffix_unit(const char *nptr, char **end,
         goto fail;
     }
     if ((val * mul >= INT64_MAX) || val < 0) {
+        retval = -ERANGE;
         goto fail;
     }
     retval = val * mul;