From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:42662) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TqQ3o-0001fE-VN for qemu-devel@nongnu.org; Wed, 02 Jan 2013 10:16:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TqQ3g-0005ew-RX for qemu-devel@nongnu.org; Wed, 02 Jan 2013 10:16:52 -0500 Received: from mx1.redhat.com ([209.132.183.28]:25896) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TqQ3g-0005ei-Bu for qemu-devel@nongnu.org; Wed, 02 Jan 2013 10:16:44 -0500 From: Stefan Hajnoczi Date: Wed, 2 Jan 2013 16:15:52 +0100 Message-Id: <1357139756-11951-15-git-send-email-stefanha@redhat.com> In-Reply-To: <1357139756-11951-1-git-send-email-stefanha@redhat.com> References: <1357139756-11951-1-git-send-email-stefanha@redhat.com> Subject: [Qemu-devel] [PATCH 14/18] cutils: change strtosz_suffix_unit function List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Anthony Liguori , Stefan Hajnoczi , liguang From: liguang 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 --- cutils.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cutils.c b/cutils.c index d06590b..80bb1dc 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; -- 1.8.0.2