cutils:change strtosz_suffix_unit function
PATCH v3 1/2 cutils:change strtosz_suffix_unit function
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.
--- cutils.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)
cutils.c +4 -2
@@ -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;
Signature · 1 line
1.7.2.5
PATCH v3 2/2 qemu-img:report size overflow error message
qemu-img will complain when qcow or qcow2
size overflow for 64 bits, report the right
message in this condition.
$./qemu-img create -f qcow2 /tmp/foo 0x10000000000000000
before change:
qemu-img: Invalid image size specified! You may use k, M, G or T suffixes for
qemu-img: kilobytes, megabytes, gigabytes and terabytes.
after change:
qemu-img: Image size must be less than 8 EiB!
--- qemu-img.c | 16 +++++++++++----- 1 files changed, 11 insertions(+), 5 deletions(-)
qemu-img.c +11 -5
@@ -347,11 +347,17 @@ static int img_create(int argc, char **argv)char *end; sval =strtosz_suffix (argv[optind++], &end,STRTOSZ_DEFSUFFIX_B );if (sval <0 || *end) { -error_report ("Invalid image size specified! You may use k, M, G or " -"T suffixes for " ); -error_report ("kilobytes, megabytes, gigabytes and terabytes." ); - ret =-1 ; - goto out; +if (sval == -ERANGE ) { +error_report ("Image size must be less than 8 EiB!" ); + ret =-1 ; + goto out; + }else { +error_report ("Invalid image size specified! You may use k, M, G or " +"T suffixes for " ); +error_report ("kilobytes, megabytes, gigabytes and terabytes." ); + ret =-1 ; + goto out; + } } img_size = (uint64_t )sval; }
Signature · 1 line
1.7.2.5
Stefan Hajnoczi
AppliedQuoted 8 lines · 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 <[email protected]>--- 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