Explicit conversions

Signed-off-by: Adrien Gallouët <adrien@gallouet.fr>
This commit is contained in:
Adrien Gallouët
2019-04-03 09:25:22 +00:00
parent a2106c248d
commit 06e165e664

36
mud.c
View File

@@ -277,11 +277,13 @@ mud_now(void)
#if defined CLOCK_REALTIME #if defined CLOCK_REALTIME
struct timespec tv; struct timespec tv;
clock_gettime(CLOCK_REALTIME, &tv); clock_gettime(CLOCK_REALTIME, &tv);
now = tv.tv_sec * MUD_ONE_SEC + tv.tv_nsec / MUD_ONE_MSEC; now = (uint64_t)tv.tv_sec * MUD_ONE_SEC
+ (uint64_t)tv.tv_nsec / MUD_ONE_MSEC;
#else #else
struct timeval tv; struct timeval tv;
gettimeofday(&tv, NULL); gettimeofday(&tv, NULL);
now = tv.tv_sec * MUD_ONE_SEC + tv.tv_usec; now = (uint64_t)tv.tv_sec * MUD_ONE_SEC
+ (uint64_t)tv.tv_usec;
#endif #endif
return MUD_TIME_MASK(now); return MUD_TIME_MASK(now);
} }
@@ -324,7 +326,7 @@ mud_unmapv4(struct sockaddr_storage *addr)
static struct mud_path * static struct mud_path *
mud_select_path(struct mud *mud, unsigned k) mud_select_path(struct mud *mud, unsigned k)
{ {
unsigned w = 0; uint64_t window = 0;
struct mud_path *last = NULL; struct mud_path *last = NULL;
for (unsigned i = 0; i < mud->count; i++) { for (unsigned i = 0; i < mud->count; i++) {
@@ -333,17 +335,17 @@ mud_select_path(struct mud *mud, unsigned k)
if (!path->window) if (!path->window)
continue; continue;
w += ((path->window << 16) + (mud->window >> 1)) / mud->window; window += ((path->window << 16) + (mud->window >> 1)) / mud->window;
last = path; last = path;
if (k <= w) if ((uint64_t)k <= window)
break; break;
} }
return last; return last;
} }
static ssize_t static int
mud_send_path(struct mud *mud, struct mud_path *path, uint64_t now, mud_send_path(struct mud *mud, struct mud_path *path, uint64_t now,
void *data, size_t size, int tc, int flags) void *data, size_t size, int tc, int flags)
{ {
@@ -426,7 +428,7 @@ mud_send_path(struct mud *mud, struct mud_path *path, uint64_t now,
path->window = 0; path->window = 0;
} }
return ret; return (int)ret;
} }
static int static int
@@ -468,13 +470,13 @@ mud_cmp_addr(struct sockaddr_storage *a, struct sockaddr_storage *b)
struct mud_path * struct mud_path *
mud_get_paths(struct mud *mud, unsigned *ret_count) mud_get_paths(struct mud *mud, unsigned *ret_count)
{ {
unsigned count = 0;
if (!ret_count) { if (!ret_count) {
errno = EINVAL; errno = EINVAL;
return NULL; return NULL;
} }
unsigned count = 0;
for (unsigned i = 0; i < mud->count; i++) { for (unsigned i = 0; i < mud->count; i++) {
struct mud_path *path = &mud->paths[i]; struct mud_path *path = &mud->paths[i];
@@ -1013,7 +1015,7 @@ mud_encrypt(struct mud *mud, uint64_t now,
mud_encrypt_opt(&mud->crypto.current, &opt); mud_encrypt_opt(&mud->crypto.current, &opt);
} }
return size; return (int)size;
} }
static int static int
@@ -1045,7 +1047,7 @@ mud_decrypt(struct mud *mud,
} }
} }
return size; return (int)size;
} }
static int static int
@@ -1192,7 +1194,7 @@ mud_decrypt_msg(struct mud *mud,
if (mud_decrypt_opt(&mud->crypto.private, &opt)) if (mud_decrypt_opt(&mud->crypto.private, &opt))
return -1; return -1;
return size; return (int)size;
} }
static void static void
@@ -1355,8 +1357,8 @@ mud_recv(struct mud *mud, void *data, size_t size)
} }
const int ret = MUD_MSG(send_time) const int ret = MUD_MSG(send_time)
? mud_decrypt_msg(mud, data, size, packet, packet_size) ? mud_decrypt_msg(mud, data, size, packet, (size_t)packet_size)
: mud_decrypt(mud, data, size, packet, packet_size); : mud_decrypt(mud, data, size, packet, (size_t)packet_size);
if (ret <= 0) { if (ret <= 0) {
mud->bad.decrypt.addr = addr; mud->bad.decrypt.addr = addr;
@@ -1378,11 +1380,11 @@ mud_recv(struct mud *mud, void *data, size_t size)
return 0; return 0;
if (MUD_MSG(send_time)) if (MUD_MSG(send_time))
mud_recv_msg(mud, path, now, send_time, data, packet_size); mud_recv_msg(mud, path, now, send_time, data, (size_t)packet_size);
path->recv.total++; path->recv.total++;
path->recv.time = now; path->recv.time = now;
path->recv.bytes += packet_size; path->recv.bytes += (size_t)packet_size;
mud->last_recv_time = now; mud->last_recv_time = now;
@@ -1535,5 +1537,5 @@ mud_send(struct mud *mud, const void *data, size_t size, unsigned tc)
} }
return mud_send_path(mud, mud_select_path(mud, k), return mud_send_path(mud, mud_select_path(mud, k),
now, packet, packet_size, tc & 255, 0); now, packet, (size_t)packet_size, tc & 255, 0);
} }