Use unsigned long in mud_set_x()

Signed-off-by: Adrien Gallouët <adrien@gallouet.fr>
This commit is contained in:
Adrien Gallouët
2018-02-11 10:06:04 +00:00
parent d8ede46d8a
commit 582eb29617
2 changed files with 23 additions and 9 deletions

24
mud.c
View File

@@ -619,27 +619,41 @@ mud_set_tc(struct mud *mud, int tc)
} }
int int
mud_set_send_timeout_msec(struct mud *mud, unsigned msec) mud_set_send_timeout(struct mud *mud, unsigned long msec)
{ {
if (!msec) { if (!msec) {
errno = EINVAL; errno = EINVAL;
return -1; return -1;
} }
mud->send_timeout = msec * MUD_ONE_MSEC; const uint64_t x = msec * MUD_ONE_MSEC;
if ((uint64_t)msec != x / MUD_ONE_MSEC) {
errno = ERANGE;
return -1;
}
mud->send_timeout = x;
return 0; return 0;
} }
int int
mud_set_time_tolerance_sec(struct mud *mud, unsigned sec) mud_set_time_tolerance(struct mud *mud, unsigned long msec)
{ {
if (!sec) { if (!msec) {
errno = EINVAL; errno = EINVAL;
return -1; return -1;
} }
mud->time_tolerance = sec * MUD_ONE_SEC; const uint64_t x = msec * MUD_ONE_MSEC;
if ((uint64_t)msec != x / MUD_ONE_MSEC) {
errno = ERANGE;
return -1;
}
mud->time_tolerance = x;
return 0; return 0;
} }

4
mud.h
View File

@@ -15,8 +15,8 @@ int mud_get_key (struct mud *, unsigned char *, size_t *);
int mud_set_mtu (struct mud *, int mtu); int mud_set_mtu (struct mud *, int mtu);
int mud_get_mtu (struct mud *); int mud_get_mtu (struct mud *);
int mud_set_send_timeout_msec (struct mud *, unsigned); int mud_set_send_timeout (struct mud *, unsigned long);
int mud_set_time_tolerance_sec (struct mud *, unsigned); int mud_set_time_tolerance (struct mud *, unsigned long);
int mud_set_tc (struct mud *, int); int mud_set_tc (struct mud *, int);
int mud_set_aes (struct mud *); int mud_set_aes (struct mud *);