aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordberg.se>2019-04-08 12:19:52 +0200
committerLinus Nordberg <linus@nordberg.se>2019-04-08 12:22:41 +0200
commita7d380a398e7c3a5a6e671cbc77e8dbcb8e1fbc6 (patch)
treefab6180f135859875526b04b380cd4838e953394
parentUse a fixed low TCP port (diff)
downloadwg-dynamic-a7d380a398e7c3a5a6e671cbc77e8dbcb8e1fbc6.tar.xz
wg-dynamic-a7d380a398e7c3a5a6e671cbc77e8dbcb8e1fbc6.zip
One uint32_t is enough
Collapse the three members of the data union into one since they have the same type. Addresses an issue found by Tharre.
-rw-r--r--common.c16
1 files changed, 7 insertions, 9 deletions
diff --git a/common.c b/common.c
index 15e46b3..194dfaa 100644
--- a/common.c
+++ b/common.c
@@ -50,9 +50,7 @@ static struct wg_dynamic_attr *parse_value(enum wg_dynamic_key key, char *value)
char *endptr;
uintmax_t uresult;
union {
- uint32_t leasetime;
- uint32_t leasestart;
- uint32_t err;
+ uint32_t uint32;
char errmsg[72];
struct wg_combined_ip ip;
} data = { 0 };
@@ -73,28 +71,28 @@ static struct wg_dynamic_attr *parse_value(enum wg_dynamic_key key, char *value)
break;
case WGKEY_LEASESTART:
- len = sizeof data.leasestart;
+ len = sizeof data.uint32;
uresult = strtoumax(value, &endptr, 10);
if (uresult > UINT32_MAX || *endptr != '\0')
return NULL;
- data.leasestart = (uint32_t)uresult;
+ data.uint32 = (uint32_t)uresult;
break;
case WGKEY_LEASETIME:
- len = sizeof data.leasetime;
+ len = sizeof data.uint32;
uresult = strtoumax(value, &endptr, 10);
if (uresult > UINT32_MAX || *endptr != '\0')
return NULL;
- data.leasetime = (uint32_t)uresult;
+ data.uint32 = (uint32_t)uresult;
break;
case WGKEY_ERRNO:
- len = sizeof data.err;
+ len = sizeof data.uint32;
uresult = strtoumax(value, &endptr, 10);
if (uresult > UINT32_MAX || *endptr != '\0')
return NULL;
- data.err = (uint32_t)uresult;
+ data.uint32 = (uint32_t)uresult;
break;
case WGKEY_ERRMSG:
strncpy(data.errmsg, value, sizeof data.errmsg);