From 0566527e70aa56e74cd29a7a09de8c0319cef637 Mon Sep 17 00:00:00 2001 From: Bostjan Skufca Jese Date: Wed, 29 Jun 2022 22:24:28 +0200 Subject: [PATCH] Fix redundant cast-to-int when INI_USE_STACK!=0 (#137) Code context (ini.c): 101: #if INI_USE_STACK 102: char line[INI_MAX_LINE]; 103: int max_line = INI_MAX_LINE; 104: #else 105: char* line; 106: size_t max_line = INI_INITIAL_ALLOC; 107: #endif ... 133: while (reader(line, (int)max_line, stream) != NULL) { SonarCloud is reporting a "code smell" due to a redundant cast to `int` at line 133. This only happens when INI_USE_STACK is true, and not otherwise, as in that case, `max_line` is of type `size_t` that gets correctly casted to `int`. This patch changes the type of `max_line` variable to `size_t` for all situations. SonarCloud report URL: https://sonarcloud.io/project/issues?pullRequest=221&issues=AYGYdhPZKkhmUWy1nsvP&open=AYGYdhPZKkhmUWy1nsvP&id=snoopy Co-authored-by: Ben Hoyt --- ini.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ini.c b/ini.c index f8a3ea3..8d3b597 100644 --- a/ini.c +++ b/ini.c @@ -100,7 +100,7 @@ int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler, /* Uses a fair bit of stack (use heap instead if you need to) */ #if INI_USE_STACK char line[INI_MAX_LINE]; - int max_line = INI_MAX_LINE; + size_t max_line = INI_MAX_LINE; #else char* line; size_t max_line = INI_INITIAL_ALLOC;