mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-02 15:23:53 -06:00
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:
parent
84760bbca9
commit
bd1386cce1
12 changed files with 86 additions and 101 deletions
|
@ -249,12 +249,12 @@ static int inet_listen_saddr(InetSocketAddress *saddr,
|
|||
|
||||
/* lookup */
|
||||
if (port_offset) {
|
||||
unsigned long long baseport;
|
||||
uint64_t baseport;
|
||||
if (strlen(port) == 0) {
|
||||
error_setg(errp, "port not specified");
|
||||
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);
|
||||
return -1;
|
||||
}
|
||||
|
@ -732,19 +732,19 @@ static bool vsock_parse_vaddr_to_sockaddr(const VsockSocketAddress *vaddr,
|
|||
struct sockaddr_vm *svm,
|
||||
Error **errp)
|
||||
{
|
||||
unsigned long long val;
|
||||
uint64_t val;
|
||||
|
||||
memset(svm, 0, sizeof(*svm));
|
||||
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) {
|
||||
error_setg(errp, "Failed to parse cid '%s'", vaddr->cid);
|
||||
return false;
|
||||
}
|
||||
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) {
|
||||
error_setg(errp, "Failed to parse port '%s'", vaddr->port);
|
||||
return false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue