From 0a87bf16693e35ed172ce8738404d9acd9545a5a Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Tue, 8 Oct 2019 19:54:08 +0200 Subject: [PATCH] Fix possible int overflow in reader cb (#88) --- ini.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ini.c b/ini.c index 71fed68..b4d5921 100644 --- a/ini.c +++ b/ini.c @@ -89,11 +89,11 @@ int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler, int max_line = INI_MAX_LINE; #else char* line; - int max_line = INI_INITIAL_ALLOC; + size_t max_line = INI_INITIAL_ALLOC; #endif #if INI_ALLOW_REALLOC && !INI_USE_STACK char* new_line; - int offset; + size_t offset; #endif char section[MAX_SECTION] = ""; char prev_name[MAX_NAME] = ""; @@ -119,7 +119,7 @@ int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler, #endif /* Scan through stream line by line */ - while (reader(line, max_line, stream) != NULL) { + while (reader(line, (int)max_line, stream) != NULL) { #if INI_ALLOW_REALLOC && !INI_USE_STACK offset = strlen(line); while (offset == max_line - 1 && line[offset - 1] != '\n') { @@ -132,7 +132,7 @@ int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler, return -2; } line = new_line; - if (reader(line + offset, max_line - offset, stream) == NULL) + if (reader(line + offset, (int)(max_line - offset), stream) == NULL) break; if (max_line >= INI_MAX_LINE) break;