Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address compiler and valgrind/sanitizer warnings #47

Merged
merged 6 commits into from
Mar 29, 2024

Conversation

PhilMiller
Copy link
Contributor

@PhilMiller PhilMiller commented Mar 29, 2024

I want to enable -Werror on the top-level ngen CI workflows. That requires that the formulation modules that we integration test build cleanly.

Changes

  • Error check file read operations fgets() and fscanf()
  • Return BMI_FAILURE on errors rather than exit()ing
  • Check for BMI_FAILURE up the Initialize() call stack
  • Add -Werror to compiler flags
  • Pin OS versions in CI so that -Werror doesn't unexpectedly change meaning
  • Initialize a variable that later gets printed
  • Free the BMI object in the test driver to avoid a leak report

Testing

Github CI

Screenshots

Warnings seen in ngen Github CI:

/home/runner/work/ngen/ngen/extern/topmodel/topmodel/src/bmi_topmodel.c: In function ‘read_init_config’:
/home/runner/work/ngen/ngen/extern/topmodel/topmodel/src/bmi_topmodel.c:191:5: error: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Werror=unused-result]
  191 |     fscanf(model->control_fptr,"%d\n",&model->stand_alone);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/runner/work/ngen/ngen/extern/topmodel/topmodel/src/bmi_topmodel.c:194:5: error: ignoring return value of ‘fgets’, declared with attribute warn_unused_result [-Werror=unused-result]
  194 |     fgets(model->title,256,model->control_fptr);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/runner/work/ngen/ngen/extern/topmodel/topmodel/src/bmi_topmodel.c:200:5: error: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Werror=unused-result]
  200 |     fscanf(model->control_fptr,"%s",input_fname);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/runner/work/ngen/ngen/extern/topmodel/topmodel/src/bmi_topmodel.c:211:5: error: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Werror=unused-result]
  211 |     fscanf(model->control_fptr,"%s",subcat_fname);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/runner/work/ngen/ngen/extern/topmodel/topmodel/src/bmi_topmodel.c:212:5: error: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Werror=unused-result]
  212 |     fscanf(model->control_fptr,"%s",params_fname);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/runner/work/ngen/ngen/extern/topmodel/topmodel/src/bmi_topmodel.c:215:5: error: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Werror=unused-result]
  215 |     fscanf(model->control_fptr,"%s",output_fname);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/runner/work/ngen/ngen/extern/topmodel/topmodel/src/bmi_topmodel.c:216:5: error: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Werror=unused-result]
  216 |     fscanf(model->control_fptr,"%s",out_hyd_fname);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/runner/work/ngen/ngen/extern/topmodel/topmodel/src/bmi_topmodel.c:235:5: error: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Werror=unused-result]
  235 |     fscanf(model->subcat_fptr,"%d %d %d",&model->num_sub_catchments,&model->imap,&model->yes_print_output);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors

Checklist

  • PR has an informative and human-readable title
  • Changes are limited to a single goal (no scope creep)
  • Code can be automatically merged (no conflicts)
  • Code follows project standards (link if applicable)
  • Passes all existing automated tests
  • Any change in functionality is tested
  • New functions are documented (with a description, list of inputs, and expected output)
  • Placeholder code is flagged / future todos are captured in comments
  • Visually tested in supported browsers and devices (see checklist below 👇)
  • Project documentation has been updated (including the "Unreleased" section of the CHANGELOG)
  • Reviewers requested with the Reviewers tool ➡️

Testing checklist

Target Environment support

  • Linux
  • macOS

@PhilMiller PhilMiller changed the title Address compiler warnings Address compiler and valgrind/sanitizer warnings Mar 29, 2024
@PhilMiller PhilMiller marked this pull request as ready for review March 29, 2024 22:43
@PhilMiller PhilMiller merged commit 5c3929d into master Mar 29, 2024
4 checks passed
@PhilMiller PhilMiller deleted the PhilMiller/warnings branch March 29, 2024 23:55
Copy link
Member

@aaraney aaraney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! Thanks, @PhilMiller for making these improvements!

Just an acknowledgment review.

@PhilMiller PhilMiller mentioned this pull request Apr 1, 2024
13 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants