Skip to content

Commit

Permalink
Fix redundant cast-to-int when INI_USE_STACK!=0 (#137)
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
bostjan and benhoyt authored Jun 29, 2022
1 parent 4bd3261 commit 0566527
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion ini.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 0566527

Please sign in to comment.