Skip to content

Comments

checks: Fix -Wunused-result compiler warnings#2166

Merged
nilason merged 6 commits intoOSGeo:mainfrom
nilason:fix_wall_warnings_10
Nov 6, 2022
Merged

checks: Fix -Wunused-result compiler warnings#2166
nilason merged 6 commits intoOSGeo:mainfrom
nilason:fix_wall_warnings_10

Conversation

@nilason
Copy link
Contributor

@nilason nilason commented Feb 4, 2022

Fixes #2128.

Also reported in #2156.

Affects:

Modules

  • d.mon
  • g.proj
  • g.rename
  • ps.map
  • r.fill.dir
  • r.grow.distance
  • r.in.ascii
  • r.in.bin
  • r.in.gridatb
  • r.in.mat
  • r.param.scale
  • r.topmodel
  • v.vol.rst

GRASS Library parts

  • lib/bitmap
  • lib/cairodriver
  • lib/db/dbmi_driver
  • lib/gis
  • lib/rst/interp_float
  • lib/vector/Vlib/

@nilason nilason mentioned this pull request Feb 4, 2022
21 tasks
@nilason nilason added this to the 8.2.0 milestone Feb 4, 2022
@nilason nilason added C Related code is in C enhancement New feature or request labels Feb 4, 2022
@wenzeslaus
Copy link
Member

Please consider splitting this to modules and library would be helpful. Not only that it will be smaller PRs, but the G_fatal... calls are much more likely to be the correct solution for modules than for the library (although I assume that's what we will end up doing anyway). We can get one of the PRs in faster.

@wenzeslaus
Copy link
Member

@BadAssassin opened similar PR to this one (#2232), but considers this one better, so that seems like +1 for merging this PR.

@nilason
Copy link
Contributor Author

nilason commented Oct 19, 2022

I just took a fresh look at this and corrected a regression on bitmap.c which happened during rebase.

Almost exclusively these fixes are file I/O related, handling return values from calls with read()/fread(), write()/fwrite(), fgets(), fscanf(), getcwd(). In general it can be said that what up till now silently failed will now at least be accompanied with a message. I believe this is ready to be merged.

@asimrp
Copy link

asimrp commented Oct 29, 2022

Looks good to me 👍

Not sure what the scope of this PR is but a quick grep through the main branch, after pulling commits from this PR, reveals some read() calls that need similar treatment. That is, the return value is used without checking for error or ignored altogether. For example, see RTreeReadBranch() and RTreeReadNode() from rtree/io.c, the three read() calls in r.drain/main.c, read_block() from raster3d/r3.in.v5d/binio.c, and several more...

The command I used is

git grep -A 3 '[^a-zA-Z_.(]read('

@nilason
Copy link
Contributor Author

nilason commented Nov 4, 2022

Looks good to me 👍

👍

Not sure what the scope of this PR is but a quick grep through the main branch, after pulling commits from this PR, reveals some read() calls that need similar treatment. That is, the return value is used without checking for error or ignored altogether. For example, see RTreeReadBranch() and RTreeReadNode() from rtree/io.c, the three read() calls in r.drain/main.c, read_block() from raster3d/r3.in.v5d/binio.c, and several more...

The aim of this PR is as the title suggests, to fix -Wunused-result compiler warnings. One step in a campaign eliminating all -Wall warnings (see eg. #2156).

@nilason
Copy link
Contributor Author

nilason commented Nov 4, 2022

This been up over half a year. If there are no objections, I will merge this in the next couple of days.

@nilason nilason merged commit c04f03a into OSGeo:main Nov 6, 2022
@nilason nilason deleted the fix_wall_warnings_10 branch November 6, 2022 21:20
ninsbl pushed a commit to ninsbl/grass that referenced this pull request Feb 17, 2023
* -Wunused-result compiler warnings addressed in following parts:

GRASS Modules:

d.mon
g.proj
g.rename
ps.map
r.fill.dir
r.grow.distance
r.in.ascii
r.in.bin
r.in.gridatb
r.in.mat
r.param.scale
r.topmodel
v.vol.rst

GRASS Library parts:

lib/bitmap
lib/cairodriver
lib/db/dbmi_driver
lib/gis
lib/rst/interp_float
lib/vector/Vlib/

Almost exclusively these fixes are file I/O related, handling return
values from calls with read()/fread(), write()/fwrite(), fgets(),
fscanf(), getcwd().

In addition, potential overflow of int before it is converted to size_t
was avoided in r.in.mat/main.c
marisn pushed a commit to marisn/grass that referenced this pull request Jun 2, 2023
* -Wunused-result compiler warnings addressed in following parts:

GRASS Modules:

d.mon
g.proj
g.rename
ps.map
r.fill.dir
r.grow.distance
r.in.ascii
r.in.bin
r.in.gridatb
r.in.mat
r.param.scale
r.topmodel
v.vol.rst

GRASS Library parts:

lib/bitmap
lib/cairodriver
lib/db/dbmi_driver
lib/gis
lib/rst/interp_float
lib/vector/Vlib/

Almost exclusively these fixes are file I/O related, handling return
values from calls with read()/fread(), write()/fwrite(), fgets(),
fscanf(), getcwd().

In addition, potential overflow of int before it is converted to size_t
was avoided in r.in.mat/main.c
@neteler neteler changed the title Fix -Wunused-result compiler warnings checks: Fix -Wunused-result compiler warnings Jun 6, 2023
neteler pushed a commit to nilason/grass that referenced this pull request Nov 7, 2023
* -Wunused-result compiler warnings addressed in following parts:

GRASS Modules:

d.mon
g.proj
g.rename
ps.map
r.fill.dir
r.grow.distance
r.in.ascii
r.in.bin
r.in.gridatb
r.in.mat
r.param.scale
r.topmodel
v.vol.rst

GRASS Library parts:

lib/bitmap
lib/cairodriver
lib/db/dbmi_driver
lib/gis
lib/rst/interp_float
lib/vector/Vlib/

Almost exclusively these fixes are file I/O related, handling return
values from calls with read()/fread(), write()/fwrite(), fgets(),
fscanf(), getcwd().

In addition, potential overflow of int before it is converted to size_t
was avoided in r.in.mat/main.c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C Related code is in C enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Warnings for -Wunused-result in GCC build

3 participants