Skip to content

Comments

Fix compiler warnings, part 1#1248

Closed
nilason wants to merge 6 commits intoOSGeo:masterfrom
nilason:fix-compiler-warnings-1
Closed

Fix compiler warnings, part 1#1248
nilason wants to merge 6 commits intoOSGeo:masterfrom
nilason:fix-compiler-warnings-1

Conversation

@nilason
Copy link
Contributor

@nilason nilason commented Jan 13, 2021

Fixes compiler warnings:

  • -Wabsolute-value
  • -Warray-bounds
  • -Wc++11-compat-deprecated-writable-strings
  • -Wdangling-else

First part addressing #1247.

There are a couple of ambivalent cases and I'm not sure how to correctly address them.
I hope for input from experienced C programmers and leave this open as a draft.

Update:

Modules / code parts directly affected:

  • imagery/i.aster.toar (partly rewritten)
  • imagery/i.evapo.time (partly rewritten)
  • lib/gmath
  • lib/imagery
  • lib/vector/neta
  • raster/r.grow.distance
  • raster/r.latlong
  • raster/r.stream.extract (commented out a part)
  • raster/r.surf.idw
  • raster/r.viewshed
  • vector/v.generalize
  • vector/v.label.sa
  • vector/v.patch

@nilason nilason mentioned this pull request Jan 13, 2021
27 tasks
@nilason nilason added this to the 8.0.0 milestone Jan 13, 2021
@nilason nilason added the help wanted Extra attention is needed label Jan 13, 2021
@nilason nilason force-pushed the fix-compiler-warnings-1 branch from b73fe25 to a05c390 Compare January 18, 2021 14:29
Copy link
Contributor Author

@nilason nilason left a comment

Choose a reason for hiding this comment

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

Updated imagery/i.aster.toar/main.c according to @metzm suggestion, hopefully I got it right.

@nilason nilason force-pushed the fix-compiler-warnings-1 branch 2 times, most recently from 0daa001 to a68cee6 Compare January 18, 2021 16:25
@nilason nilason marked this pull request as ready for review January 18, 2021 18:00
@nilason
Copy link
Contributor Author

nilason commented Jan 18, 2021

This is now ready for review. Please pay special attention to i.aster.toar, which has been partly re-written by @metzm and r.stream.extract where a part of code has been commented out (per suggestion by @metzm).

@nilason nilason removed the help wanted Extra attention is needed label Jan 18, 2021
@metzm
Copy link
Contributor

metzm commented Jan 21, 2021

Looks good to me, ready to merge.

There are probably some other modules with wrong array indexing, but I recommend to put these issues in a separate PR if needed.

@nilason nilason force-pushed the fix-compiler-warnings-1 branch from 9281283 to a86a4b3 Compare January 22, 2021 10:53
@nilason
Copy link
Contributor Author

nilason commented Jan 22, 2021

Looks good to me, ready to merge.

Thanks a lot!

I did rearrange the commits: separated the fixes for i.aster.toar and i.evapo.time to one commit each.

There are probably some other modules with wrong array indexing, but I recommend to put these issues in a separate PR if needed.

At the moment these two are the only places reported by clang.

Copy link
Contributor

@metzm metzm left a comment

Choose a reason for hiding this comment

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

Interesting how many occurrences of abs() needed to be replaced with fabs()!
Thanks for your work, IMHO now ready to merge.

@nilason
Copy link
Contributor Author

nilason commented Jan 29, 2021

If there are no objections, I will take the liberty to merge in the next couple of days.

Copy link
Member

@wenzeslaus wenzeslaus left a comment

Choose a reason for hiding this comment

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

+1, but I'm also wondering about that commented out code in stream extract. I don't see anything useful in r.watershed blame.

I think, if it is just wrong, it should be deleted with a proper commit message (it is in the history after all if needed). If it is servers as a reminder of something, a comment should be added saying why it is there instead of leaving the reader wondering.

Commenting out all code would indeed fix all or most of compiler warnings, but that would be certainly an unexpected thing to find behind a "fix warnings commit". 😄

@nilason
Copy link
Contributor Author

nilason commented Jan 30, 2021

I think, if it is just wrong, it should be deleted with a proper commit message (it is in the history after all if needed). If it is servers as a reminder of something, a comment should be added saying why it is there instead of leaving the reader wondering.

Commenting out all code would indeed fix all or most of compiler warnings, but that would be certainly an unexpected thing to find behind a "fix warnings commit". 😄

Good point. Although I can live with commented out code (for readily available reminder in case...), it certainly need a commit (with message) on its own. Do you have any suggestion, @metzm?

@nilason nilason force-pushed the fix-compiler-warnings-1 branch from a86a4b3 to d6b1721 Compare January 30, 2021 16:15
@nilason
Copy link
Contributor Author

nilason commented Jan 30, 2021

I separated the commented out code in r.stream.extract to a single distinct commit. The commit message may of course be improved...

@metzm
Copy link
Contributor

metzm commented Jan 31, 2021

I think, if it is just wrong, it should be deleted with a proper commit message (it is in the history after all if needed). If it is servers as a reminder of something, a comment should be added saying why it is there instead of leaving the reader wondering.
Commenting out all code would indeed fix all or most of compiler warnings, but that would be certainly an unexpected thing to find behind a "fix warnings commit". smile

Good point. Although I can live with commented out code (for readily available reminder in case...), it certainly need a commit (with message) on its own. Do you have any suggestion, @metzm?

Delete the commented out code, no need to keep it.

@nilason nilason force-pushed the fix-compiler-warnings-1 branch from d6b1721 to 8687b82 Compare February 1, 2021 07:40
@nilason
Copy link
Contributor Author

nilason commented Feb 1, 2021

Apparently there is no way for me to merge this without sqashing all commits.
It would be preferable to keep the commits separate. Suggestion anyone?

@neteler
Copy link
Member

neteler commented Feb 2, 2021

It might work if I cherry pick to master locally and then push. What do you think, shall I give it a try?

Yes, please give it a try.

nilason added a commit that referenced this pull request Feb 2, 2021
as Option->answer is declared as as "char *".

Addresses -Wc++11-compat-deprecated-writable-strings compiler warnings.
nilason added a commit that referenced this pull request Feb 2, 2021
Addresses -Wdangling-else compiler warning.
nilason added a commit that referenced this pull request Feb 2, 2021
to respect array bounds: avoid call to array index, which is past the
end of the array. (#1248)

Addresses -Warray-bounds compiler warnings.

Co-authored-by: Markus Metz <[email protected]>
Co-authored-by: Huidae Cho <[email protected]>
nilason added a commit that referenced this pull request Feb 2, 2021
to respect array bounds: avoid call to array index, which is past the
end of the array. (#1248)

Addresses -Warray-bounds compiler warnings.
nilason added a commit that referenced this pull request Feb 2, 2021
according to given argument type. (#1248)

Addresses -Wabsolute-value compiler warnings.
nilason added a commit that referenced this pull request Feb 2, 2021
for setting main drainage direction to A* path if possible. (#1248)

Co-authored-by: Markus Metz <[email protected]>
@nilason
Copy link
Contributor Author

nilason commented Feb 2, 2021

Merged through cherry picking. Closing this manually.
Thanks a bunch for all the help!

@nilason nilason closed this Feb 2, 2021
@nilason nilason deleted the fix-compiler-warnings-1 branch February 2, 2021 14:39
marisn pushed a commit to marisn/grass that referenced this pull request Mar 22, 2021
as Option->answer is declared as as "char *".

Addresses -Wc++11-compat-deprecated-writable-strings compiler warnings.
marisn pushed a commit to marisn/grass that referenced this pull request Mar 22, 2021
Addresses -Wdangling-else compiler warning.
marisn pushed a commit to marisn/grass that referenced this pull request Mar 22, 2021
to respect array bounds: avoid call to array index, which is past the
end of the array. (OSGeo#1248)

Addresses -Warray-bounds compiler warnings.

Co-authored-by: Markus Metz <[email protected]>
Co-authored-by: Huidae Cho <[email protected]>
marisn pushed a commit to marisn/grass that referenced this pull request Mar 22, 2021
to respect array bounds: avoid call to array index, which is past the
end of the array. (OSGeo#1248)

Addresses -Warray-bounds compiler warnings.
marisn pushed a commit to marisn/grass that referenced this pull request Mar 22, 2021
according to given argument type. (OSGeo#1248)

Addresses -Wabsolute-value compiler warnings.
marisn pushed a commit to marisn/grass that referenced this pull request Mar 22, 2021
for setting main drainage direction to A* path if possible. (OSGeo#1248)

Co-authored-by: Markus Metz <[email protected]>
ninsbl pushed a commit to ninsbl/grass that referenced this pull request Oct 26, 2022
as Option->answer is declared as as "char *".

Addresses -Wc++11-compat-deprecated-writable-strings compiler warnings.
ninsbl pushed a commit to ninsbl/grass that referenced this pull request Oct 26, 2022
Addresses -Wdangling-else compiler warning.
ninsbl pushed a commit to ninsbl/grass that referenced this pull request Oct 26, 2022
to respect array bounds: avoid call to array index, which is past the
end of the array. (OSGeo#1248)

Addresses -Warray-bounds compiler warnings.

Co-authored-by: Markus Metz <[email protected]>
Co-authored-by: Huidae Cho <[email protected]>
ninsbl pushed a commit to ninsbl/grass that referenced this pull request Oct 26, 2022
to respect array bounds: avoid call to array index, which is past the
end of the array. (OSGeo#1248)

Addresses -Warray-bounds compiler warnings.
ninsbl pushed a commit to ninsbl/grass that referenced this pull request Oct 26, 2022
according to given argument type. (OSGeo#1248)

Addresses -Wabsolute-value compiler warnings.
ninsbl pushed a commit to ninsbl/grass that referenced this pull request Oct 26, 2022
for setting main drainage direction to A* path if possible. (OSGeo#1248)

Co-authored-by: Markus Metz <[email protected]>
ninsbl pushed a commit to ninsbl/grass that referenced this pull request Feb 17, 2023
as Option->answer is declared as as "char *".

Addresses -Wc++11-compat-deprecated-writable-strings compiler warnings.
ninsbl pushed a commit to ninsbl/grass that referenced this pull request Feb 17, 2023
Addresses -Wdangling-else compiler warning.
ninsbl pushed a commit to ninsbl/grass that referenced this pull request Feb 17, 2023
to respect array bounds: avoid call to array index, which is past the
end of the array. (OSGeo#1248)

Addresses -Warray-bounds compiler warnings.

Co-authored-by: Markus Metz <[email protected]>
Co-authored-by: Huidae Cho <[email protected]>
ninsbl pushed a commit to ninsbl/grass that referenced this pull request Feb 17, 2023
to respect array bounds: avoid call to array index, which is past the
end of the array. (OSGeo#1248)

Addresses -Warray-bounds compiler warnings.
ninsbl pushed a commit to ninsbl/grass that referenced this pull request Feb 17, 2023
according to given argument type. (OSGeo#1248)

Addresses -Wabsolute-value compiler warnings.
ninsbl pushed a commit to ninsbl/grass that referenced this pull request Feb 17, 2023
for setting main drainage direction to A* path if possible. (OSGeo#1248)

Co-authored-by: Markus Metz <[email protected]>
petrasovaa added a commit that referenced this pull request Oct 28, 2025
…obust (#6543)

This block got removed as part of compiler warnings cleanup #1248, but the removal broke special cases (#6541).
The intention of r.stream.extract is to use external flow accumulation for stream extraction, but if in doubt follow the A* search direction, i.e. if (fabs(wat_nbr[np_side]) >= max_acc).
Restoring this deleted code block in addition to #6554 should make r.stream.extract robust for special cases as reported in #6541.
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.

5 participants