From 11c8d7a22b0d29278d9cc88b1a50ab974a1e6e6f Mon Sep 17 00:00:00 2001 From: Test_User Date: Sun, 18 Jun 2023 19:28:52 -0400 Subject: Add -Wsign-conversion, change related things to match as desired, move gnutls_record_recv to tls.h/tls.c --- Makefile | 2 +- commands.c | 4 ++-- main.c | 14 ++------------ tls.c | 2 ++ tls.h | 11 +++++++++++ utils.c | 2 +- 6 files changed, 19 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index 9c832ec..4b76cad 100644 --- a/Makefile +++ b/Makefile @@ -28,7 +28,7 @@ #INCLUDEFLAGS = -CFLAGS += $(INCLUDEFLAGS) -D_REENTRANT -ggdb3 -Wall -Wextra -Wno-unused-parameter $(shell pkg-config gnutls --cflags) +CFLAGS += $(INCLUDEFLAGS) -D_REENTRANT -ggdb3 -Wall -Wextra -Wsign-conversion -Wno-unused-parameter $(shell pkg-config gnutls --cflags) LDFLAGS = -lpthread $(shell pkg-config gnutls --libs) diff --git a/commands.c b/commands.c index d0d6d02..0938ee2 100644 --- a/commands.c +++ b/commands.c @@ -93,7 +93,7 @@ static struct pref_type_suff { }; int sus_command(struct string sender, struct string original_message, struct string to, uint64_t argc, struct string *argv) { - uint64_t index = random() % (sizeof(sus_strings)/sizeof(sus_strings[0])); + uint64_t index = (uint64_t)random() % (sizeof(sus_strings)/sizeof(sus_strings[0])); SEND(sus_strings[index].pref); if (sus_strings[index].type == 0) @@ -112,7 +112,7 @@ static struct command_def sus_command_def = { }; int cr_command(struct string sender, struct string original_message, struct string to, uint64_t argc, struct string *argv) { - uint64_t index = random() % (sizeof(cr_strings)/sizeof(cr_strings[0])); + uint64_t index = (uint64_t)random() % (sizeof(cr_strings)/sizeof(cr_strings[0])); SEND(cr_strings[index].pref); if (cr_strings[index].type == 0) diff --git a/main.c b/main.c index 3618105..0fdd429 100644 --- a/main.c +++ b/main.c @@ -57,7 +57,7 @@ void *client_loop(void *ign) { if (len < 0) new_len = 0; else - new_len = len; + new_len = (size_t)len; } pthread_mutex_lock(&send_lock); @@ -230,18 +230,8 @@ int main(void) { struct string full_msg = {malloc(0), 0}; while (1) { char data[512]; - uint64_t new_len; pthread_mutex_unlock(&send_lock); - { - int len; - do { - len = gnutls_record_recv(session, data, 512); - } while (len == GNUTLS_E_AGAIN || len == GNUTLS_E_INTERRUPTED); - if (len < 0) - new_len = 0; - else - new_len = len; - } + uint64_t new_len = RECV(data, sizeof(data)); pthread_mutex_lock(&send_lock); if (new_len == 0) { diff --git a/tls.c b/tls.c index b173d82..54cf47d 100644 --- a/tls.c +++ b/tls.c @@ -86,3 +86,5 @@ int connect_tls(void) { return 0; } + +extern inline size_t RECV(char *buf, size_t buflen); // Should force it to get compiled into tls.o diff --git a/tls.h b/tls.h index c21e85f..116512d 100644 --- a/tls.h +++ b/tls.h @@ -33,3 +33,14 @@ extern gnutls_session_t session; extern int connect_tls(void); + +inline size_t RECV(char *buf, size_t buflen) { + int len; + do { + len = gnutls_record_recv(session, buf, buflen); + } while (len == GNUTLS_E_AGAIN || len == GNUTLS_E_INTERRUPTED); + if (len < 0) + return 0; + else + return (size_t)len; +} diff --git a/utils.c b/utils.c index f8dca52..d8bb7bd 100644 --- a/utils.c +++ b/utils.c @@ -50,7 +50,7 @@ uint64_t str_to_unsigned(struct string str, uint8_t *err) { case '8': case '9': val *= 10; - val += str.data[0] - 0x30; + val += (uint8_t)(str.data[0] - 0x30); break; default: *err = 1; -- cgit v1.2.3