Skip to content

Commit

Permalink
Fix unchecked fgets() return values
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilMiller authored and aaraney committed Apr 2, 2024
1 parent 44bb30c commit a3d82b1
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/bmi_cfe.c
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,8 @@ int read_init_config_cfe(const char* config_file, cfe_state_struct* model)

for (i = 0; i < config_line_count; i++) {
char *param_key, *param_value, *param_units;
fgets(config_line, max_config_line_length + 1, fp);
if (fgets(config_line, max_config_line_length + 1, fp) == NULL)
return BMI_FAILURE;
#if CFE_DEBUG >= 3
printf("Line value: ['%s']\n", config_line);
#endif
Expand Down Expand Up @@ -1252,12 +1253,14 @@ static int Initialize (Bmi *self, const char *file)
long year, month, day, hour, minute;
double dsec;
// First read the header line
fgets(line_str, max_forcing_line_length + 1, ffp);
if (fgets(line_str, max_forcing_line_length + 1, ffp) == NULL)
return BMI_FAILURE;

aorc_forcing_data_cfe forcings;

for (i = 0; i < cfe_bmi_data_ptr->num_timesteps; i++) {
fgets(line_str, max_forcing_line_length + 1, ffp); // read in a line of AORC data.
if (fgets(line_str, max_forcing_line_length + 1, ffp) == NULL) // read in a line of AORC data.
return BMI_FAILURE;
parse_aorc_line_cfe(line_str, &year, &month, &day, &hour, &minute, &dsec, &forcings);
#if CFE_DEBUG > 0
printf("Forcing data: [%s]\n", line_str);
Expand Down

0 comments on commit a3d82b1

Please sign in to comment.