From 582eb2961784e30ea1d067c2ab4e792f9a4c3d0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Gallou=C3=ABt?= Date: Sun, 11 Feb 2018 10:06:04 +0000 Subject: [PATCH] Use unsigned long in mud_set_x() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Adrien Gallouët --- mud.c | 24 +++++++++++++++++++----- mud.h | 8 ++++---- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/mud.c b/mud.c index 621d878..b212b91 100644 --- a/mud.c +++ b/mud.c @@ -619,27 +619,41 @@ mud_set_tc(struct mud *mud, int tc) } int -mud_set_send_timeout_msec(struct mud *mud, unsigned msec) +mud_set_send_timeout(struct mud *mud, unsigned long msec) { if (!msec) { errno = EINVAL; 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; } 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; 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; } diff --git a/mud.h b/mud.h index 41d94c6..fae6cda 100644 --- a/mud.h +++ b/mud.h @@ -15,10 +15,10 @@ int mud_get_key (struct mud *, unsigned char *, size_t *); int mud_set_mtu (struct mud *, int mtu); int mud_get_mtu (struct mud *); -int mud_set_send_timeout_msec (struct mud *, unsigned); -int mud_set_time_tolerance_sec (struct mud *, unsigned); -int mud_set_tc (struct mud *, int); -int mud_set_aes (struct mud *); +int mud_set_send_timeout (struct mud *, unsigned long); +int mud_set_time_tolerance (struct mud *, unsigned long); +int mud_set_tc (struct mud *, int); +int mud_set_aes (struct mud *); int mud_peer (struct mud *, const char *, int);