Skip to content

Commit

Permalink
Correct error check on fscanf
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilMiller committed Mar 29, 2024
1 parent 4c65a5e commit c542279
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/bmi_topmodel.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ int read_init_config(const char* config_file, topmodel_model* model) {
//Read the stand_alone T/F
//note: newline is needed here!
ret = fscanf(model->control_fptr,"%d\n",&model->stand_alone);
if (ret != 0)
if (ret != 1)
return BMI_FAILURE;

//Read the title line, up to 255 characters, of the the file
Expand All @@ -205,7 +205,7 @@ int read_init_config(const char* config_file, topmodel_model* model) {
char input_fname[MAX_FILENAME_LENGTH];
//It might be worth always scanning this line, but only opening the file if not STAND_ALONE
ret = fscanf(model->control_fptr,"%s",input_fname);
if (ret != 0)
if (ret != 1)
return BMI_FAILURE;

//If stand_alone TRUE, read inputs from input file
Expand All @@ -218,18 +218,18 @@ int read_init_config(const char* config_file, topmodel_model* model) {

char subcat_fname[MAX_FILENAME_LENGTH],params_fname[MAX_FILENAME_LENGTH];
ret = fscanf(model->control_fptr,"%s",subcat_fname);
if (ret != 0)
if (ret != 1)
return BMI_FAILURE;
ret = fscanf(model->control_fptr,"%s",params_fname);
if (ret != 0)
if (ret != 1)
return BMI_FAILURE;

char output_fname[MAX_FILENAME_LENGTH],out_hyd_fname[MAX_FILENAME_LENGTH];
ret = fscanf(model->control_fptr,"%s",output_fname);
if (ret != 0)
if (ret != 1)
return BMI_FAILURE;
ret = fscanf(model->control_fptr,"%s",out_hyd_fname);
if (ret != 0)
if (ret != 1)
return BMI_FAILURE;

//Attempt to read the parsed input file names, bail if they cannot be read/created
Expand All @@ -250,7 +250,7 @@ int read_init_config(const char* config_file, topmodel_model* model) {
// just use model->stand_alone as control switch
// move line to init_config() with others
ret = fscanf(model->subcat_fptr,"%d %d %d",&model->num_sub_catchments,&model->imap,&model->yes_print_output);
if (ret != 0)
if (ret != 3)
return BMI_FAILURE;

// Attempt to read the output file names only if printing to file
Expand Down

0 comments on commit c542279

Please sign in to comment.