Skip to content

Commit 0566527

Browse files
bostjanbenhoyt
andauthored
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 <[email protected]>
1 parent 4bd3261 commit 0566527

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

ini.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,
100100
/* Uses a fair bit of stack (use heap instead if you need to) */
101101
#if INI_USE_STACK
102102
char line[INI_MAX_LINE];
103-
int max_line = INI_MAX_LINE;
103+
size_t max_line = INI_MAX_LINE;
104104
#else
105105
char* line;
106106
size_t max_line = INI_INITIAL_ALLOC;

0 commit comments

Comments
 (0)