diff --git a/src/parser.c b/src/parser.c index 49b035db05722d13d1ce48129b8fae8bfc1ad86b..db98f7893250b93c5ec78b42bf14431c5238dcee 100644 --- a/src/parser.c +++ b/src/parser.c @@ -276,7 +276,13 @@ static void parse_value(char *line, struct swift_params *params) { find_duplicate_params(params, tmpStr); strcpy(section, tmpSectionName); - strcpy(params->section[params->sectionCount++].name, tmpSectionName); + strcpy(params->section[params->sectionCount].name, tmpSectionName); + if (params->sectionCount == PARSER_MAX_NO_OF_SECTIONS - 1) { + error( + "Maximal number of sections in parameter file reached. Aborting !"); + } else { + params->sectionCount++; + } inSection = 1; isFirstParam = 1; } else { @@ -294,7 +300,14 @@ static void parse_value(char *line, struct swift_params *params) { /* Must be a standalone parameter so no need to prefix name with a * section. */ strcpy(params->data[params->paramCount].name, tmpStr); - strcpy(params->data[params->paramCount++].value, token); + strcpy(params->data[params->paramCount].value, token); + if (params->paramCount == PARSER_MAX_NO_OF_PARAMS - 1) { + error( + "MMaximal number of parameters in parameter file reached. Aborting " + "!"); + } else { + params->paramCount++; + } inSection = 0; isFirstParam = 1; } @@ -346,7 +359,13 @@ static void parse_section_param(char *line, int *isFirstParam, find_duplicate_params(params, paramName); strcpy(params->data[params->paramCount].name, paramName); - strcpy(params->data[params->paramCount++].value, token); + strcpy(params->data[params->paramCount].value, token); + if (params->paramCount == PARSER_MAX_NO_OF_PARAMS - 1) { + error( + "MMaximal number of parameters in parameter file reached. Aborting !"); + } else { + params->paramCount++; + } } /** @@ -376,7 +395,8 @@ int parser_get_param_int(const struct swift_params *params, const char *name) { } } - error("Cannot find '%s' in the structure, in file '%s'.", name,params->fileName); + error("Cannot find '%s' in the structure, in file '%s'.", name, + params->fileName); return 0; } @@ -408,7 +428,8 @@ char parser_get_param_char(const struct swift_params *params, } } - error("Cannot find '%s' in the structure, in file '%s'.", name,params->fileName); + error("Cannot find '%s' in the structure, in file '%s'.", name, + params->fileName); return 0; } @@ -440,7 +461,8 @@ float parser_get_param_float(const struct swift_params *params, } } - error("Cannot find '%s' in the structure, in file '%s'.", name,params->fileName); + error("Cannot find '%s' in the structure, in file '%s'.", name, + params->fileName); return 0.f; } @@ -471,7 +493,8 @@ double parser_get_param_double(const struct swift_params *params, } } - error("Cannot find '%s' in the structure, in file '%s'.", name,params->fileName); + error("Cannot find '%s' in the structure, in file '%s'.", name, + params->fileName); return 0.; } diff --git a/src/parser.h b/src/parser.h index 2d50ddc49bf2231235bbb73040b067f77462d33e..6670bfaebf874c06bca1d078de104456a69a1b29 100644 --- a/src/parser.h +++ b/src/parser.h @@ -24,7 +24,8 @@ /* Some constants. */ #define PARSER_MAX_LINE_SIZE 256 -#define PARSER_MAX_NO_OF_PARAMS 512 +#define PARSER_MAX_NO_OF_PARAMS 256 +#define PARSER_MAX_NO_OF_SECTIONS 64 /* A parameter in the input file */ struct parameter { @@ -38,7 +39,7 @@ struct section { /* The array of parameters read from a file */ struct swift_params { - struct section section[PARSER_MAX_NO_OF_PARAMS]; + struct section section[PARSER_MAX_NO_OF_SECTIONS]; struct parameter data[PARSER_MAX_NO_OF_PARAMS]; int sectionCount; int paramCount;