mirror of https://github.com/xqemu/xqemu.git
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. Signed-off-by: liguang <lig.fnst@cn.fujitsu.com> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
parent
9e72c45033
commit
37edbf7ea8
6
cutils.c
6
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,
|
* 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
|
* 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,
|
int64_t strtosz_suffix_unit(const char *nptr, char **end,
|
||||||
const char default_suffix, int64_t unit)
|
const char default_suffix, int64_t unit)
|
||||||
{
|
{
|
||||||
int64_t retval = -1;
|
int64_t retval = -EINVAL;
|
||||||
char *endptr;
|
char *endptr;
|
||||||
unsigned char c;
|
unsigned char c;
|
||||||
int mul_required = 0;
|
int mul_required = 0;
|
||||||
|
@ -246,6 +247,7 @@ int64_t strtosz_suffix_unit(const char *nptr, char **end,
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
if ((val * mul >= INT64_MAX) || val < 0) {
|
if ((val * mul >= INT64_MAX) || val < 0) {
|
||||||
|
retval = -ERANGE;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
retval = val * mul;
|
retval = val * mul;
|
||||||
|
|
Loading…
Reference in New Issue