From 94eff0a4bb0853bc30cbb131e38878f34e28c0f6 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Sun, 17 Jan 2021 14:22:23 +0100 Subject: [PATCH] Fix size_t incorrectly assigned to int The function control_msg_serialize() returns a size_t. --- app/src/controller.c | 4 ++-- app/tests/test_control_msg_serialize.c | 24 ++++++++++++------------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/app/src/controller.c b/app/src/controller.c index 6bfb80d3..da90fbf1 100644 --- a/app/src/controller.c +++ b/app/src/controller.c @@ -60,12 +60,12 @@ static bool process_msg(struct controller *controller, const struct control_msg *msg) { static unsigned char serialized_msg[CONTROL_MSG_MAX_SIZE]; - int length = control_msg_serialize(msg, serialized_msg); + size_t length = control_msg_serialize(msg, serialized_msg); if (!length) { return false; } int w = net_send_all(controller->control_socket, serialized_msg, length); - return w == length; + return (size_t) w == length; } static int diff --git a/app/tests/test_control_msg_serialize.c b/app/tests/test_control_msg_serialize.c index ffd5f300..dc6e0821 100644 --- a/app/tests/test_control_msg_serialize.c +++ b/app/tests/test_control_msg_serialize.c @@ -17,7 +17,7 @@ static void test_serialize_inject_keycode(void) { }; unsigned char buf[CONTROL_MSG_MAX_SIZE]; - int size = control_msg_serialize(&msg, buf); + size_t size = control_msg_serialize(&msg, buf); assert(size == 14); const unsigned char expected[] = { @@ -39,7 +39,7 @@ static void test_serialize_inject_text(void) { }; unsigned char buf[CONTROL_MSG_MAX_SIZE]; - int size = control_msg_serialize(&msg, buf); + size_t size = control_msg_serialize(&msg, buf); assert(size == 18); const unsigned char expected[] = { @@ -59,7 +59,7 @@ static void test_serialize_inject_text_long(void) { msg.inject_text.text = text; unsigned char buf[CONTROL_MSG_MAX_SIZE]; - int size = control_msg_serialize(&msg, buf); + size_t size = control_msg_serialize(&msg, buf); assert(size == 5 + CONTROL_MSG_INJECT_TEXT_MAX_LENGTH); unsigned char expected[5 + CONTROL_MSG_INJECT_TEXT_MAX_LENGTH]; @@ -95,7 +95,7 @@ static void test_serialize_inject_touch_event(void) { }; unsigned char buf[CONTROL_MSG_MAX_SIZE]; - int size = control_msg_serialize(&msg, buf); + size_t size = control_msg_serialize(&msg, buf); assert(size == 28); const unsigned char expected[] = { @@ -130,7 +130,7 @@ static void test_serialize_inject_scroll_event(void) { }; unsigned char buf[CONTROL_MSG_MAX_SIZE]; - int size = control_msg_serialize(&msg, buf); + size_t size = control_msg_serialize(&msg, buf); assert(size == 21); const unsigned char expected[] = { @@ -149,7 +149,7 @@ static void test_serialize_back_or_screen_on(void) { }; unsigned char buf[CONTROL_MSG_MAX_SIZE]; - int size = control_msg_serialize(&msg, buf); + size_t size = control_msg_serialize(&msg, buf); assert(size == 1); const unsigned char expected[] = { @@ -164,7 +164,7 @@ static void test_serialize_expand_notification_panel(void) { }; unsigned char buf[CONTROL_MSG_MAX_SIZE]; - int size = control_msg_serialize(&msg, buf); + size_t size = control_msg_serialize(&msg, buf); assert(size == 1); const unsigned char expected[] = { @@ -179,7 +179,7 @@ static void test_serialize_collapse_notification_panel(void) { }; unsigned char buf[CONTROL_MSG_MAX_SIZE]; - int size = control_msg_serialize(&msg, buf); + size_t size = control_msg_serialize(&msg, buf); assert(size == 1); const unsigned char expected[] = { @@ -194,7 +194,7 @@ static void test_serialize_get_clipboard(void) { }; unsigned char buf[CONTROL_MSG_MAX_SIZE]; - int size = control_msg_serialize(&msg, buf); + size_t size = control_msg_serialize(&msg, buf); assert(size == 1); const unsigned char expected[] = { @@ -213,7 +213,7 @@ static void test_serialize_set_clipboard(void) { }; unsigned char buf[CONTROL_MSG_MAX_SIZE]; - int size = control_msg_serialize(&msg, buf); + size_t size = control_msg_serialize(&msg, buf); assert(size == 19); const unsigned char expected[] = { @@ -234,7 +234,7 @@ static void test_serialize_set_screen_power_mode(void) { }; unsigned char buf[CONTROL_MSG_MAX_SIZE]; - int size = control_msg_serialize(&msg, buf); + size_t size = control_msg_serialize(&msg, buf); assert(size == 2); const unsigned char expected[] = { @@ -250,7 +250,7 @@ static void test_serialize_rotate_device(void) { }; unsigned char buf[CONTROL_MSG_MAX_SIZE]; - int size = control_msg_serialize(&msg, buf); + size_t size = control_msg_serialize(&msg, buf); assert(size == 1); const unsigned char expected[] = {