cutils: Adjust signature of parse_uint[_full]

It's already confusing that we have two very similar functions for
wrapping the parse of a 64-bit unsigned value, differing mainly on
whether they permit leading '-'.  Adjust the signature of parse_uint()
and parse_uint_full() to be like all of qemu_strto*(): put the result
parameter last, use the same types (uint64_t and unsigned long long
have the same width, but are not always the same type), and mark
endptr const (this latter change only affects the rare caller of
parse_uint).  Adjust all callers in the tree.

While at it, note that since cutils.c already includes:

    QEMU_BUILD_BUG_ON(sizeof(int64_t) != sizeof(long long));

we are guaranteed that the result of parse_uint* cannot exceed
UINT64_MAX (or the build would have failed), so we can drop
pre-existing dead comparisons in opts-visitor.c that were never false.

Reviewed-by: Hanna Czenczek <hreitz@redhat.com>
Message-Id: <20230522190441.64278-8-eblake@redhat.com>
[eblake: Drop dead code spotted by Markus]
Signed-off-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
Eric Blake 2023-05-22 14:04:29 -05:00
parent 84760bbca9
commit bd1386cce1
12 changed files with 86 additions and 101 deletions

View File

@ -35,8 +35,8 @@
static uint32_t toui32(const char *str) static uint32_t toui32(const char *str)
{ {
unsigned long long ret; uint64_t ret;
if (parse_uint_full(str, &ret, 10) || ret > UINT32_MAX) { if (parse_uint_full(str, 10, &ret) || ret > UINT32_MAX) {
dolog("Invalid integer value `%s'\n", str); dolog("Invalid integer value `%s'\n", str);
exit(1); exit(1);
} }

View File

@ -424,7 +424,7 @@ static struct glfs *qemu_gluster_glfs_init(BlockdevOptionsGluster *gconf,
int ret; int ret;
int old_errno; int old_errno;
SocketAddressList *server; SocketAddressList *server;
unsigned long long port; uint64_t port;
glfs = glfs_find_preopened(gconf->volume); glfs = glfs_find_preopened(gconf->volume);
if (glfs) { if (glfs) {
@ -445,7 +445,7 @@ static struct glfs *qemu_gluster_glfs_init(BlockdevOptionsGluster *gconf,
server->value->u.q_unix.path, 0); server->value->u.q_unix.path, 0);
break; break;
case SOCKET_ADDRESS_TYPE_INET: case SOCKET_ADDRESS_TYPE_INET:
if (parse_uint_full(server->value->u.inet.port, &port, 10) < 0 || if (parse_uint_full(server->value->u.inet.port, 10, &port) < 0 ||
port > 65535) { port > 65535) {
error_setg(errp, "'%s' is not a valid port number", error_setg(errp, "'%s' is not a valid port number",
server->value->u.inet.port); server->value->u.inet.port);

View File

@ -114,13 +114,13 @@ static int nfs_parse_uri(const char *filename, QDict *options, Error **errp)
qdict_put_str(options, "path", uri->path); qdict_put_str(options, "path", uri->path);
for (i = 0; i < qp->n; i++) { for (i = 0; i < qp->n; i++) {
unsigned long long val; uint64_t val;
if (!qp->p[i].value) { if (!qp->p[i].value) {
error_setg(errp, "Value for NFS parameter expected: %s", error_setg(errp, "Value for NFS parameter expected: %s",
qp->p[i].name); qp->p[i].name);
goto out; goto out;
} }
if (parse_uint_full(qp->p[i].value, &val, 0)) { if (parse_uint_full(qp->p[i].value, 0, &val)) {
error_setg(errp, "Illegal value for NFS parameter: %s", error_setg(errp, "Illegal value for NFS parameter: %s",
qp->p[i].name); qp->p[i].name);
goto out; goto out;

View File

@ -341,10 +341,10 @@ static bool parse_stats_intervals(BlockAcctStats *stats, QList *intervals,
switch (qobject_type(entry->value)) { switch (qobject_type(entry->value)) {
case QTYPE_QSTRING: { case QTYPE_QSTRING: {
unsigned long long length; uint64_t length;
const char *str = qstring_get_str(qobject_to(QString, const char *str = qstring_get_str(qobject_to(QString,
entry->value)); entry->value));
if (parse_uint_full(str, &length, 10) == 0 && if (parse_uint_full(str, 10, &length) == 0 &&
length > 0 && length <= UINT_MAX) { length > 0 && length <= UINT_MAX) {
block_acct_add_interval(stats, (unsigned) length); block_acct_add_interval(stats, (unsigned) length);
} else { } else {

View File

@ -69,7 +69,7 @@ static void
ivshmem_server_parse_args(IvshmemServerArgs *args, int argc, char *argv[]) ivshmem_server_parse_args(IvshmemServerArgs *args, int argc, char *argv[])
{ {
int c; int c;
unsigned long long v; uint64_t v;
Error *err = NULL; Error *err = NULL;
while ((c = getopt(argc, argv, "hvFp:S:m:M:l:n:")) != -1) { while ((c = getopt(argc, argv, "hvFp:S:m:M:l:n:")) != -1) {
@ -112,7 +112,7 @@ ivshmem_server_parse_args(IvshmemServerArgs *args, int argc, char *argv[])
break; break;
case 'n': /* number of vectors */ case 'n': /* number of vectors */
if (parse_uint_full(optarg, &v, 0) < 0) { if (parse_uint_full(optarg, 0, &v) < 0) {
fprintf(stderr, "cannot parse n_vectors\n"); fprintf(stderr, "cannot parse n_vectors\n");
ivshmem_server_help(argv[0]); ivshmem_server_help(argv[0]);
exit(1); exit(1);

View File

@ -163,9 +163,8 @@ int qemu_strtou64(const char *nptr, const char **endptr, int base,
int qemu_strtod(const char *nptr, const char **endptr, double *result); int qemu_strtod(const char *nptr, const char **endptr, double *result);
int qemu_strtod_finite(const char *nptr, const char **endptr, double *result); int qemu_strtod_finite(const char *nptr, const char **endptr, double *result);
int parse_uint(const char *s, unsigned long long *value, char **endptr, int parse_uint(const char *s, const char **endptr, int base, uint64_t *value);
int base); int parse_uint_full(const char *s, int base, uint64_t *value);
int parse_uint_full(const char *s, unsigned long long *value, int base);
int qemu_strtosz(const char *nptr, const char **end, uint64_t *result); int qemu_strtosz(const char *nptr, const char **end, uint64_t *result);
int qemu_strtosz_MiB(const char *nptr, const char **end, uint64_t *result); int qemu_strtosz_MiB(const char *nptr, const char **end, uint64_t *result);

View File

@ -454,8 +454,8 @@ opts_type_uint64(Visitor *v, const char *name, uint64_t *obj, Error **errp)
OptsVisitor *ov = to_ov(v); OptsVisitor *ov = to_ov(v);
const QemuOpt *opt; const QemuOpt *opt;
const char *str; const char *str;
unsigned long long val; uint64_t val;
char *endptr; const char *endptr;
if (ov->list_mode == LM_UNSIGNED_INTERVAL) { if (ov->list_mode == LM_UNSIGNED_INTERVAL) {
*obj = ov->range_next.u; *obj = ov->range_next.u;
@ -471,18 +471,18 @@ opts_type_uint64(Visitor *v, const char *name, uint64_t *obj, Error **errp)
/* we've gotten past lookup_scalar() */ /* we've gotten past lookup_scalar() */
assert(ov->list_mode == LM_NONE || ov->list_mode == LM_IN_PROGRESS); assert(ov->list_mode == LM_NONE || ov->list_mode == LM_IN_PROGRESS);
if (parse_uint(str, &val, &endptr, 0) == 0 && val <= UINT64_MAX) { if (parse_uint(str, &endptr, 0, &val) == 0) {
if (*endptr == '\0') { if (*endptr == '\0') {
*obj = val; *obj = val;
processed(ov, name); processed(ov, name);
return true; return true;
} }
if (*endptr == '-' && ov->list_mode == LM_IN_PROGRESS) { if (*endptr == '-' && ov->list_mode == LM_IN_PROGRESS) {
unsigned long long val2; uint64_t val2;
str = endptr + 1; str = endptr + 1;
if (parse_uint_full(str, &val2, 0) == 0 && if (parse_uint_full(str, 0, &val2) == 0 &&
val2 <= UINT64_MAX && val <= val2 && val <= val2 &&
val2 - val < OPTS_VISITOR_RANGE_MAX) { val2 - val < OPTS_VISITOR_RANGE_MAX) {
ov->range_next.u = val; ov->range_next.u = val;
ov->range_limit.u = val2; ov->range_limit.u = val2;

View File

@ -31,12 +31,11 @@
static void test_parse_uint_null(void) static void test_parse_uint_null(void)
{ {
unsigned long long i = 999; uint64_t i = 999;
char f = 'X'; const char *endptr = "somewhere";
char *endptr = &f;
int r; int r;
r = parse_uint(NULL, &i, &endptr, 0); r = parse_uint(NULL, &endptr, 0, &i);
g_assert_cmpint(r, ==, -EINVAL); g_assert_cmpint(r, ==, -EINVAL);
g_assert_cmpuint(i, ==, 0); g_assert_cmpuint(i, ==, 0);
@ -45,13 +44,12 @@ static void test_parse_uint_null(void)
static void test_parse_uint_empty(void) static void test_parse_uint_empty(void)
{ {
unsigned long long i = 999; uint64_t i = 999;
char f = 'X'; const char *endptr = "somewhere";
char *endptr = &f;
const char *str = ""; const char *str = "";
int r; int r;
r = parse_uint(str, &i, &endptr, 0); r = parse_uint(str, &endptr, 0, &i);
g_assert_cmpint(r, ==, -EINVAL); g_assert_cmpint(r, ==, -EINVAL);
g_assert_cmpuint(i, ==, 0); g_assert_cmpuint(i, ==, 0);
@ -60,13 +58,12 @@ static void test_parse_uint_empty(void)
static void test_parse_uint_whitespace(void) static void test_parse_uint_whitespace(void)
{ {
unsigned long long i = 999; uint64_t i = 999;
char f = 'X'; const char *endptr = "somewhere";
char *endptr = &f;
const char *str = " \t "; const char *str = " \t ";
int r; int r;
r = parse_uint(str, &i, &endptr, 0); r = parse_uint(str, &endptr, 0, &i);
g_assert_cmpint(r, ==, -EINVAL); g_assert_cmpint(r, ==, -EINVAL);
g_assert_cmpuint(i, ==, 0); g_assert_cmpuint(i, ==, 0);
@ -76,13 +73,12 @@ static void test_parse_uint_whitespace(void)
static void test_parse_uint_invalid(void) static void test_parse_uint_invalid(void)
{ {
unsigned long long i = 999; uint64_t i = 999;
char f = 'X'; const char *endptr = "somewhere";
char *endptr = &f;
const char *str = " \t xxx"; const char *str = " \t xxx";
int r; int r;
r = parse_uint(str, &i, &endptr, 0); r = parse_uint(str, &endptr, 0, &i);
g_assert_cmpint(r, ==, -EINVAL); g_assert_cmpint(r, ==, -EINVAL);
g_assert_cmpuint(i, ==, 0); g_assert_cmpuint(i, ==, 0);
@ -92,13 +88,12 @@ static void test_parse_uint_invalid(void)
static void test_parse_uint_trailing(void) static void test_parse_uint_trailing(void)
{ {
unsigned long long i = 999; uint64_t i = 999;
char f = 'X'; const char *endptr = "somewhere";
char *endptr = &f;
const char *str = "123xxx"; const char *str = "123xxx";
int r; int r;
r = parse_uint(str, &i, &endptr, 0); r = parse_uint(str, &endptr, 0, &i);
g_assert_cmpint(r, ==, 0); g_assert_cmpint(r, ==, 0);
g_assert_cmpuint(i, ==, 123); g_assert_cmpuint(i, ==, 123);
@ -107,13 +102,12 @@ static void test_parse_uint_trailing(void)
static void test_parse_uint_correct(void) static void test_parse_uint_correct(void)
{ {
unsigned long long i = 999; uint64_t i = 999;
char f = 'X'; const char *endptr = "somewhere";
char *endptr = &f;
const char *str = "123"; const char *str = "123";
int r; int r;
r = parse_uint(str, &i, &endptr, 0); r = parse_uint(str, &endptr, 0, &i);
g_assert_cmpint(r, ==, 0); g_assert_cmpint(r, ==, 0);
g_assert_cmpuint(i, ==, 123); g_assert_cmpuint(i, ==, 123);
@ -122,13 +116,12 @@ static void test_parse_uint_correct(void)
static void test_parse_uint_octal(void) static void test_parse_uint_octal(void)
{ {
unsigned long long i = 999; uint64_t i = 999;
char f = 'X'; const char *endptr = "somewhere";
char *endptr = &f;
const char *str = "0123"; const char *str = "0123";
int r; int r;
r = parse_uint(str, &i, &endptr, 0); r = parse_uint(str, &endptr, 0, &i);
g_assert_cmpint(r, ==, 0); g_assert_cmpint(r, ==, 0);
g_assert_cmpuint(i, ==, 0123); g_assert_cmpuint(i, ==, 0123);
@ -137,13 +130,12 @@ static void test_parse_uint_octal(void)
static void test_parse_uint_decimal(void) static void test_parse_uint_decimal(void)
{ {
unsigned long long i = 999; uint64_t i = 999;
char f = 'X'; const char *endptr = "somewhere";
char *endptr = &f;
const char *str = "0123"; const char *str = "0123";
int r; int r;
r = parse_uint(str, &i, &endptr, 10); r = parse_uint(str, &endptr, 10, &i);
g_assert_cmpint(r, ==, 0); g_assert_cmpint(r, ==, 0);
g_assert_cmpuint(i, ==, 123); g_assert_cmpuint(i, ==, 123);
@ -152,13 +144,12 @@ static void test_parse_uint_decimal(void)
static void test_parse_uint_llong_max(void) static void test_parse_uint_llong_max(void)
{ {
unsigned long long i = 999; uint64_t i = 999;
char f = 'X'; const char *endptr = "somewhere";
char *endptr = &f;
char *str = g_strdup_printf("%llu", (unsigned long long)LLONG_MAX + 1); char *str = g_strdup_printf("%llu", (unsigned long long)LLONG_MAX + 1);
int r; int r;
r = parse_uint(str, &i, &endptr, 0); r = parse_uint(str, &endptr, 0, &i);
g_assert_cmpint(r, ==, 0); g_assert_cmpint(r, ==, 0);
g_assert_cmpuint(i, ==, (unsigned long long)LLONG_MAX + 1); g_assert_cmpuint(i, ==, (unsigned long long)LLONG_MAX + 1);
@ -169,13 +160,12 @@ static void test_parse_uint_llong_max(void)
static void test_parse_uint_max(void) static void test_parse_uint_max(void)
{ {
unsigned long long i = 999; uint64_t i = 999;
char f = 'X'; const char *endptr = "somewhere";
char *endptr = &f;
char *str = g_strdup_printf("%llu", ULLONG_MAX); char *str = g_strdup_printf("%llu", ULLONG_MAX);
int r; int r;
r = parse_uint(str, &i, &endptr, 0); r = parse_uint(str, &endptr, 0, &i);
g_assert_cmpint(r, ==, 0); g_assert_cmpint(r, ==, 0);
g_assert_cmpuint(i, ==, ULLONG_MAX); g_assert_cmpuint(i, ==, ULLONG_MAX);
@ -186,32 +176,31 @@ static void test_parse_uint_max(void)
static void test_parse_uint_overflow(void) static void test_parse_uint_overflow(void)
{ {
unsigned long long i; uint64_t i;
char f = 'X'; const char *endptr;
char *endptr;
const char *str; const char *str;
int r; int r;
i = 999; i = 999;
endptr = &f; endptr = "somewhere";
str = "99999999999999999999999999999999999999"; str = "99999999999999999999999999999999999999";
r = parse_uint(str, &i, &endptr, 0); r = parse_uint(str, &endptr, 0, &i);
g_assert_cmpint(r, ==, -ERANGE); g_assert_cmpint(r, ==, -ERANGE);
g_assert_cmpuint(i, ==, ULLONG_MAX); g_assert_cmpuint(i, ==, ULLONG_MAX);
g_assert_true(endptr == str + strlen(str)); g_assert_true(endptr == str + strlen(str));
i = 999; i = 999;
endptr = &f; endptr = "somewhere";
str = "0x10000000000000000"; /* 65 bits, 64-bit sign bit clear */ str = "0x10000000000000000"; /* 65 bits, 64-bit sign bit clear */
r = parse_uint(str, &i, &endptr, 0); r = parse_uint(str, &endptr, 0, &i);
g_assert_cmpint(r, ==, -ERANGE); g_assert_cmpint(r, ==, -ERANGE);
g_assert_cmpuint(i, ==, ULLONG_MAX); g_assert_cmpuint(i, ==, ULLONG_MAX);
g_assert_true(endptr == str + strlen(str)); g_assert_true(endptr == str + strlen(str));
i = 999; i = 999;
endptr = &f; endptr = "somewhere";
str = "0x18000000080000000"; /* 65 bits, 64-bit sign bit set */ str = "0x18000000080000000"; /* 65 bits, 64-bit sign bit set */
r = parse_uint(str, &i, &endptr, 0); r = parse_uint(str, &endptr, 0, &i);
g_assert_cmpint(r, ==, -ERANGE); g_assert_cmpint(r, ==, -ERANGE);
g_assert_cmpuint(i, ==, ULLONG_MAX); g_assert_cmpuint(i, ==, ULLONG_MAX);
g_assert_true(endptr == str + strlen(str)); g_assert_true(endptr == str + strlen(str));
@ -219,24 +208,23 @@ static void test_parse_uint_overflow(void)
static void test_parse_uint_negative(void) static void test_parse_uint_negative(void)
{ {
unsigned long long i; uint64_t i;
char f = 'X'; const char *endptr;
char *endptr;
const char *str; const char *str;
int r; int r;
i = 999; i = 999;
endptr = &f; endptr = "somewhere";
str = " \t -321"; str = " \t -321";
r = parse_uint(str, &i, &endptr, 0); r = parse_uint(str, &endptr, 0, &i);
g_assert_cmpint(r, ==, -ERANGE); g_assert_cmpint(r, ==, -ERANGE);
g_assert_cmpuint(i, ==, 0); g_assert_cmpuint(i, ==, 0);
g_assert_true(endptr == str + strlen(str)); g_assert_true(endptr == str + strlen(str));
i = 999; i = 999;
endptr = &f; endptr = "somewhere";
str = "-0xffffffff00000001"; str = "-0xffffffff00000001";
r = parse_uint(str, &i, &endptr, 0); r = parse_uint(str, &endptr, 0, &i);
g_assert_cmpint(r, ==, -ERANGE); g_assert_cmpint(r, ==, -ERANGE);
g_assert_cmpuint(i, ==, 0); g_assert_cmpuint(i, ==, 0);
g_assert_true(endptr == str + strlen(str)); g_assert_true(endptr == str + strlen(str));
@ -244,13 +232,12 @@ static void test_parse_uint_negative(void)
static void test_parse_uint_negzero(void) static void test_parse_uint_negzero(void)
{ {
unsigned long long i = 999; uint64_t i = 999;
char f = 'X'; const char *endptr = "somewhere";
char *endptr = &f;
const char *str = " -0"; const char *str = " -0";
int r; int r;
r = parse_uint(str, &i, &endptr, 0); r = parse_uint(str, &endptr, 0, &i);
g_assert_cmpint(r, ==, -ERANGE); g_assert_cmpint(r, ==, -ERANGE);
g_assert_cmpuint(i, ==, 0); g_assert_cmpuint(i, ==, 0);
@ -259,11 +246,11 @@ static void test_parse_uint_negzero(void)
static void test_parse_uint_full_trailing(void) static void test_parse_uint_full_trailing(void)
{ {
unsigned long long i = 999; uint64_t i = 999;
const char *str = "123xxx"; const char *str = "123xxx";
int r; int r;
r = parse_uint_full(str, &i, 0); r = parse_uint_full(str, 0, &i);
g_assert_cmpint(r, ==, -EINVAL); g_assert_cmpint(r, ==, -EINVAL);
g_assert_cmpuint(i, ==, 0); g_assert_cmpuint(i, ==, 0);
@ -271,11 +258,11 @@ static void test_parse_uint_full_trailing(void)
static void test_parse_uint_full_correct(void) static void test_parse_uint_full_correct(void)
{ {
unsigned long long i = 999; uint64_t i = 999;
const char *str = "123"; const char *str = "123";
int r; int r;
r = parse_uint_full(str, &i, 0); r = parse_uint_full(str, 0, &i);
g_assert_cmpint(r, ==, 0); g_assert_cmpint(r, ==, 0);
g_assert_cmpuint(i, ==, 123); g_assert_cmpuint(i, ==, 123);
@ -284,11 +271,11 @@ static void test_parse_uint_full_correct(void)
static void test_parse_uint_full_erange_junk(void) static void test_parse_uint_full_erange_junk(void)
{ {
/* FIXME - inconsistent with qemu_strto* which favors EINVAL */ /* FIXME - inconsistent with qemu_strto* which favors EINVAL */
unsigned long long i = 999; uint64_t i = 999;
const char *str = "-2junk"; const char *str = "-2junk";
int r; int r;
r = parse_uint_full(str, &i, 0); r = parse_uint_full(str, 0, &i);
g_assert_cmpint(r, ==, -ERANGE /* FIXME -EINVAL */); g_assert_cmpint(r, ==, -ERANGE /* FIXME -EINVAL */);
g_assert_cmpuint(i, ==, 0); g_assert_cmpuint(i, ==, 0);

View File

@ -3728,7 +3728,7 @@ static int vnc_display_get_address(const char *addrstr,
} else { } else {
const char *port; const char *port;
size_t hostlen; size_t hostlen;
unsigned long long baseport = 0; uint64_t baseport = 0;
InetSocketAddress *inet; InetSocketAddress *inet;
port = strrchr(addrstr, ':'); port = strrchr(addrstr, ':');
@ -3776,7 +3776,7 @@ static int vnc_display_get_address(const char *addrstr,
} }
} else { } else {
int offset = reverse ? 0 : 5900; int offset = reverse ? 0 : 5900;
if (parse_uint_full(port, &baseport, 10) < 0) { if (parse_uint_full(port, 10, &baseport) < 0) {
error_setg(errp, "can't convert to a number: %s", port); error_setg(errp, "can't convert to a number: %s", port);
goto cleanup; goto cleanup;
} }

View File

@ -722,10 +722,10 @@ const char *qemu_strchrnul(const char *s, int c)
* parse_uint: * parse_uint:
* *
* @s: String to parse * @s: String to parse
* @value: Destination for parsed integer value
* @endptr: Destination for pointer to first character not consumed, must * @endptr: Destination for pointer to first character not consumed, must
* not be %NULL * not be %NULL
* @base: integer base, between 2 and 36 inclusive, or 0 * @base: integer base, between 2 and 36 inclusive, or 0
* @value: Destination for parsed integer value
* *
* Parse unsigned integer * Parse unsigned integer
* *
@ -748,8 +748,7 @@ const char *qemu_strchrnul(const char *s, int c)
* *
* Else, set *@value to the parsed integer, and return 0. * Else, set *@value to the parsed integer, and return 0.
*/ */
int parse_uint(const char *s, unsigned long long *value, char **endptr, int parse_uint(const char *s, const char **endptr, int base, uint64_t *value)
int base)
{ {
int r = 0; int r = 0;
char *endp = (char *)s; char *endp = (char *)s;
@ -793,8 +792,8 @@ out:
* parse_uint_full: * parse_uint_full:
* *
* @s: String to parse * @s: String to parse
* @value: Destination for parsed integer value
* @base: integer base, between 2 and 36 inclusive, or 0 * @base: integer base, between 2 and 36 inclusive, or 0
* @value: Destination for parsed integer value
* *
* Parse unsigned integer from entire string * Parse unsigned integer from entire string
* *
@ -803,12 +802,12 @@ out:
* characters are present after a non-overflowing parsed number, the * characters are present after a non-overflowing parsed number, the
* function will return -EINVAL, and *@v will be set to 0. * function will return -EINVAL, and *@v will be set to 0.
*/ */
int parse_uint_full(const char *s, unsigned long long *value, int base) int parse_uint_full(const char *s, int base, uint64_t *value)
{ {
char *endp; const char *endp;
int r; int r;
r = parse_uint(s, value, &endp, base); r = parse_uint(s, &endp, base, value);
if (r < 0) { if (r < 0) {
return r; return r;
} }

View File

@ -89,8 +89,8 @@ void qemu_guest_random_seed_thread_part2(uint64_t seed)
int qemu_guest_random_seed_main(const char *optarg, Error **errp) int qemu_guest_random_seed_main(const char *optarg, Error **errp)
{ {
unsigned long long seed; uint64_t seed;
if (parse_uint_full(optarg, &seed, 0)) { if (parse_uint_full(optarg, 0, &seed)) {
error_setg(errp, "Invalid seed number: %s", optarg); error_setg(errp, "Invalid seed number: %s", optarg);
return -1; return -1;
} else { } else {

View File

@ -249,12 +249,12 @@ static int inet_listen_saddr(InetSocketAddress *saddr,
/* lookup */ /* lookup */
if (port_offset) { if (port_offset) {
unsigned long long baseport; uint64_t baseport;
if (strlen(port) == 0) { if (strlen(port) == 0) {
error_setg(errp, "port not specified"); error_setg(errp, "port not specified");
return -1; return -1;
} }
if (parse_uint_full(port, &baseport, 10) < 0) { if (parse_uint_full(port, 10, &baseport) < 0) {
error_setg(errp, "can't convert to a number: %s", port); error_setg(errp, "can't convert to a number: %s", port);
return -1; return -1;
} }
@ -732,19 +732,19 @@ static bool vsock_parse_vaddr_to_sockaddr(const VsockSocketAddress *vaddr,
struct sockaddr_vm *svm, struct sockaddr_vm *svm,
Error **errp) Error **errp)
{ {
unsigned long long val; uint64_t val;
memset(svm, 0, sizeof(*svm)); memset(svm, 0, sizeof(*svm));
svm->svm_family = AF_VSOCK; svm->svm_family = AF_VSOCK;
if (parse_uint_full(vaddr->cid, &val, 10) < 0 || if (parse_uint_full(vaddr->cid, 10, &val) < 0 ||
val > UINT32_MAX) { val > UINT32_MAX) {
error_setg(errp, "Failed to parse cid '%s'", vaddr->cid); error_setg(errp, "Failed to parse cid '%s'", vaddr->cid);
return false; return false;
} }
svm->svm_cid = val; svm->svm_cid = val;
if (parse_uint_full(vaddr->port, &val, 10) < 0 || if (parse_uint_full(vaddr->port, 10, &val) < 0 ||
val > UINT32_MAX) { val > UINT32_MAX) {
error_setg(errp, "Failed to parse port '%s'", vaddr->port); error_setg(errp, "Failed to parse port '%s'", vaddr->port);
return false; return false;