Skip to content
Snippets Groups Projects
Commit 21aef1a0 authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Parser reports an error if there are too many params.

parent 15b49080
No related branches found
No related tags found
1 merge request!173Parameter file in snapshot
......@@ -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.;
}
......
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment