mirror of
https://github.com/yuzu-emu/unicorn.git
synced 2025-02-02 04:41:03 +00:00
util/cutils: Change qemu_strtosz*() from int64_t to uint64_t
This will permit its use in parse_option_size(). Backports commit f46bfdbfc8f95cf65d7818ef68a801e063c40332 from qemu
This commit is contained in:
parent
8650d0213c
commit
89d8e58718
|
@ -131,9 +131,9 @@ int qemu_strtoi64(const char *nptr, const char **endptr, int base,
|
||||||
int qemu_strtou64(const char *nptr, const char **endptr, int base,
|
int qemu_strtou64(const char *nptr, const char **endptr, int base,
|
||||||
uint64_t *result);
|
uint64_t *result);
|
||||||
|
|
||||||
int qemu_strtosz(const char *nptr, char **end, int64_t *result);
|
int qemu_strtosz(const char *nptr, char **end, uint64_t *result);
|
||||||
int qemu_strtosz_MiB(const char *nptr, char **end, int64_t *result);
|
int qemu_strtosz_MiB(const char *nptr, char **end, uint64_t *result);
|
||||||
int qemu_strtosz_metric(const char *nptr, char **end, int64_t *result);
|
int qemu_strtosz_metric(const char *nptr, char **end, uint64_t *result);
|
||||||
|
|
||||||
#define K_BYTE (1ULL << 10)
|
#define K_BYTE (1ULL << 10)
|
||||||
#define M_BYTE (1ULL << 20)
|
#define M_BYTE (1ULL << 20)
|
||||||
|
|
|
@ -2182,10 +2182,10 @@ static void x86_cpu_parse_featurestr(CPUState *cs, char *features,
|
||||||
/* Special case: */
|
/* Special case: */
|
||||||
if (!strcmp(name, "tsc-freq")) {
|
if (!strcmp(name, "tsc-freq")) {
|
||||||
int ret;
|
int ret;
|
||||||
int64_t tsc_freq;
|
uint64_t tsc_freq;
|
||||||
|
|
||||||
ret = qemu_strtosz_metric(val, NULL, &tsc_freq);
|
ret = qemu_strtosz_metric(val, NULL, &tsc_freq);
|
||||||
if (ret < 0) {
|
if (ret < 0 || tsc_freq > INT64_MAX) {
|
||||||
error_setg(errp, "bad numerical value %s", val);
|
error_setg(errp, "bad numerical value %s", val);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -156,7 +156,7 @@ static int64_t suffix_mul(char suffix, int64_t unit)
|
||||||
*/
|
*/
|
||||||
static int do_strtosz(const char *nptr, char **end,
|
static int do_strtosz(const char *nptr, char **end,
|
||||||
const char default_suffix, int64_t unit,
|
const char default_suffix, int64_t unit,
|
||||||
int64_t *result)
|
uint64_t *result)
|
||||||
{
|
{
|
||||||
int retval;
|
int retval;
|
||||||
char *endptr;
|
char *endptr;
|
||||||
|
@ -186,7 +186,11 @@ static int do_strtosz(const char *nptr, char **end,
|
||||||
retval = -EINVAL;
|
retval = -EINVAL;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
if ((val * mul >= INT64_MAX) || val < 0) {
|
/*
|
||||||
|
* Values >= 0xfffffffffffffc00 overflow uint64_t after their trip
|
||||||
|
* through double (53 bits of precision).
|
||||||
|
*/
|
||||||
|
if ((val * mul >= 0xfffffffffffffc00) || val < 0) {
|
||||||
retval = -ERANGE;
|
retval = -ERANGE;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
@ -203,17 +207,17 @@ out:
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
int qemu_strtosz(const char *nptr, char **end, int64_t *result)
|
int qemu_strtosz(const char *nptr, char **end, uint64_t *result)
|
||||||
{
|
{
|
||||||
return do_strtosz(nptr, end, 'B', 1024, result);
|
return do_strtosz(nptr, end, 'B', 1024, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
int qemu_strtosz_MiB(const char *nptr, char **end, int64_t *result)
|
int qemu_strtosz_MiB(const char *nptr, char **end, uint64_t *result)
|
||||||
{
|
{
|
||||||
return do_strtosz(nptr, end, 'M', 1024, result);
|
return do_strtosz(nptr, end, 'M', 1024, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
int qemu_strtosz_metric(const char *nptr, char **end, int64_t *result)
|
int qemu_strtosz_metric(const char *nptr, char **end, uint64_t *result)
|
||||||
{
|
{
|
||||||
return do_strtosz(nptr, end, 'B', 1000, result);
|
return do_strtosz(nptr, end, 'B', 1000, result);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue