Check the value passed to the grib_set -d option

This commit is contained in:
Shahram Najm 2019-02-05 15:47:20 +00:00
parent 8881d760df
commit efe074293d
1 changed files with 7 additions and 1 deletions

View File

@ -240,7 +240,13 @@ int grib_process_runtime_options(grib_context* context,int argc,char** argv,grib
options->gts=grib_options_on("g"); options->gts=grib_options_on("g");
if (grib_options_on("d:")) { if (grib_options_on("d:")) {
options->constant=atof(grib_options_get_option("d:")); char* endPtr = NULL; /* for error handling */
const char* optionStr = grib_options_get_option("d:");
options->constant=strtod(optionStr, &endPtr);
if(*endPtr) {
fprintf(stderr, "Invalid number for -d option: '%s'\n", optionStr);
exit(1);
}
options->repack=1; options->repack=1;
} }