* [Qemu-devel] [PATCH v3 1/2] cutils:change strtosz_suffix_unit function
@ 2012-12-17 1:49 liguang
2012-12-17 1:49 ` [Qemu-devel] [PATCH v3 2/2] qemu-img:report size overflow error message liguang
2012-12-18 14:25 ` [Qemu-devel] [PATCH v3 1/2] cutils:change strtosz_suffix_unit function Stefan Hajnoczi
0 siblings, 2 replies; 3+ messages in thread
From: liguang @ 2012-12-17 1:49 UTC (permalink / raw)
To: stefanha, armbru, imammedo, qemu-devel; +Cc: 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 <lig.fnst@cn.fujitsu.com>
---
cutils.c | 6 ++++--
1 files changed, 4 insertions(+), 2 deletions(-)
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;
--
1.7.2.5
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [Qemu-devel] [PATCH v3 2/2] qemu-img:report size overflow error message
2012-12-17 1:49 [Qemu-devel] [PATCH v3 1/2] cutils:change strtosz_suffix_unit function liguang
@ 2012-12-17 1:49 ` liguang
2012-12-18 14:25 ` [Qemu-devel] [PATCH v3 1/2] cutils:change strtosz_suffix_unit function Stefan Hajnoczi
1 sibling, 0 replies; 3+ messages in thread
From: liguang @ 2012-12-17 1:49 UTC (permalink / raw)
To: stefanha, armbru, imammedo, qemu-devel; +Cc: liguang
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!
Signed-off-by: liguang <lig.fnst@cn.fujitsu.com>
---
qemu-img.c | 16 +++++++++++-----
1 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/qemu-img.c b/qemu-img.c
index e29e01b..203e3cb 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -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;
}
--
1.7.2.5
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH v3 1/2] cutils:change strtosz_suffix_unit function
2012-12-17 1:49 [Qemu-devel] [PATCH v3 1/2] cutils:change strtosz_suffix_unit function liguang
2012-12-17 1:49 ` [Qemu-devel] [PATCH v3 2/2] qemu-img:report size overflow error message liguang
@ 2012-12-18 14:25 ` Stefan Hajnoczi
1 sibling, 0 replies; 3+ messages in thread
From: Stefan Hajnoczi @ 2012-12-18 14:25 UTC (permalink / raw)
To: liguang; +Cc: imammedo, armbru, qemu-devel
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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-12-18 14:25 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-17 1:49 [Qemu-devel] [PATCH v3 1/2] cutils:change strtosz_suffix_unit function liguang
2012-12-17 1:49 ` [Qemu-devel] [PATCH v3 2/2] qemu-img:report size overflow error message liguang
2012-12-18 14:25 ` [Qemu-devel] [PATCH v3 1/2] cutils:change strtosz_suffix_unit function Stefan Hajnoczi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).