From 168fb03e6329b011a222b36c15d5ca08afa946e8 Mon Sep 17 00:00:00 2001 Message-Id: <168fb03e6329b011a222b36c15d5ca08afa946e8.1425657843.git.jen@redhat.com> In-Reply-To: References: From: liguang Date: Mon, 17 Dec 2012 09:49:22 +0800 Subject: [CHANGE 02/11] cutils: change strtosz_suffix_unit function To: rhvirt-patches@redhat.com, jen@redhat.com 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 Signed-off-by: Stefan Hajnoczi (cherry picked from commit 37edbf7ea8067262a5c3d8bbe4786139348c8311) RHEL 6: This patch required manual conflict resolution. We're missing commits ea5b1cfe and a7261486 downstream, and especially the latter depends on other unrelated patches, so I refrained from cherry-picking them. Signed-off-by: Kevin Wolf Signed-off-by: Jeff E. Nelson --- cutils.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cutils.c b/cutils.c index 7389127..580346f 100644 --- a/cutils.c +++ b/cutils.c @@ -392,11 +392,12 @@ int fcntl_setfl(int fd, int flag) * 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. A valid value must be terminated by - * whitespace, ',' or '\0'. Return -1 on error. + * whitespace, ',' or '\0'. Return -ERANGE on overflow, Return -EINVAL + * on other error. */ int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix) { - int64_t retval = -1; + int64_t retval = -EINVAL; char *endptr; unsigned char c, d; int mul_required = 0; @@ -457,6 +458,7 @@ int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix) } } if ((val * mul >= INT64_MAX) || val < 0) { + retval = -ERANGE; goto fail; } retval = val * mul; -- 2.1.0