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

Fix warnings to support -Werror in Github CI #35

Merged
merged 6 commits into from
Mar 29, 2024

Conversation

PhilMiller
Copy link
Contributor

@PhilMiller PhilMiller commented Mar 29, 2024

Changes

  • Match printf format specifiers to argument types
  • Check return values from fgets

Testing

  1. CI workflows

Screenshots

This is what I was getting in ngen's CI workflows. More turned up in the rest of the codebase here

/home/runner/work/ngen/ngen/extern/evapotranspiration/evapotranspiration/src/bmi_pet.c: In function ‘Initialize’:
/home/runner/work/ngen/ngen/extern/evapotranspiration/evapotranspiration/src/bmi_pet.c:80:76: error: format ‘%e’ expects argument of type ‘double’, but argument 2 has type ‘long int’ [-Werror=format=]
   80 |             printf("the number of time steps from the forcing file is: %8.6e \n", pet->bmi.num_timesteps);
      |                                                                        ~~~~^      ~~~~~~~~~~~~~~~~~~~~~~
      |                                                                            |              |
      |                                                                            double         long int
      |                                                                        %8.6ld
/home/runner/work/ngen/ngen/extern/evapotranspiration/evapotranspiration/src/bmi_pet.c: In function ‘Get_current_time’:
/home/runner/work/ngen/ngen/extern/evapotranspiration/evapotranspiration/src/bmi_pet.c:517:45: error: format ‘%ld’ expects argument of type ‘long int’, but argument 2 has type ‘double’ [-Werror=format=]
  517 |         printf("Current model time step: '%ld'\n", ((pet_model *) self->data)->bmi.current_time_step);
      |                                           ~~^      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                             |                                     |
      |                                             long int                              double
      |                                           %f
/home/runner/work/ngen/ngen/extern/evapotranspiration/evapotranspiration/src/bmi_pet.c: In function ‘read_init_config_pet’:
/home/runner/work/ngen/ngen/extern/evapotranspiration/evapotranspiration/src/bmi_pet.c:763:26: error: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long int’ [-Werror=format=]
  763 |                 printf("%d\n", model->bmi.num_timesteps);
      |                         ~^     ~~~~~~~~~~~~~~~~~~~~~~~~
      |                          |               |
      |                          int             long int
      |                         %ld
/home/runner/work/ngen/ngen/extern/evapotranspiration/evapotranspiration/src/bmi_pet.c:611:9: error: ignoring return value of ‘fgets’, declared with attribute warn_unused_result [-Werror=unused-result]
  611 |         fgets(config_line, max_config_line_length + 1, fp);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/runner/work/ngen/ngen/extern/evapotranspiration/evapotranspiration/src/bmi_pet.c: In function ‘Initialize’:
/home/runner/work/ngen/ngen/extern/evapotranspiration/evapotranspiration/src/bmi_pet.c:77:9: error: ignoring return value of ‘fgets’, declared with attribute warn_unused_result [-Werror=unused-result]
   77 |         fgets(line_str, max_forcing_line_length + 1, ffp);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/runner/work/ngen/ngen/extern/evapotranspiration/evapotranspiration/src/bmi_pet.c:84:13: error: ignoring return value of ‘fgets’, declared with attribute warn_unused_result [-Werror=unused-result]
   84 |             fgets(line_str, max_forcing_line_length + 1, ffp);  // read in a line of AORC data.
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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
Copy link
Contributor Author

@program-- Could you please have a look?

@PhilMiller PhilMiller marked this pull request as ready for review March 29, 2024 19:17
@program--
Copy link

@madMatchstick @aaraney

@aaraney aaraney merged commit 15807d3 into NOAA-OWP:master Mar 29, 2024
4 checks passed
@PhilMiller PhilMiller deleted the PhilMiller/warnings branch April 1, 2024 20:49
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