r.geomorphon: fix uninitialized memory access in main loop#6924
r.geomorphon: fix uninitialized memory access in main loop#6924sumitchintanwar wants to merge 2 commits intoOSGeo:mainfrom
Conversation
This fixes 2550 Valgrind errors by initializing distance variables and refactoring the main loop into an if/else structure to protect border cells.
wenzeslaus
left a comment
There was a problem hiding this comment.
Thank you for this PR. This is generally in the right direction. There is couple of issues, mainly this changes a lot of lines without a clear relation to the original Valgrind issue.
Related to the size of the change. The code block change would be easier to review with a full test in place backing up the results. There are two regression tests in place for this tool, but they are limited in terms of what they are testing. Would you be willing to contribute new tests for this tool? Ideally, in a separate PR which would be merged before this one if it runs.
I see there are three things combined here, the Valgrind-related fix, the flow clarification, and all the other fixes (now inits, but possibly changes of scope).
Separating these and having better tests in place will make it easier to review.
| } | ||
|
|
||
| if (opt_output[o_ternary]->answer) | ||
| ((CELL *)rasters[o_ternary].buffer)[col] = | ||
| determine_ternary(pattern->pattern); |
There was a problem hiding this comment.
Is this change necessary for the fix of the Valgrid issue? I agree that the change should be made, but perhaps separately from the Valgrid fix.
@wenzeslaus Thanks for the feeback. Yes, I’m willing to contribute new tests for this tool. I’ll prepare a separate PR to improve test coverage and submit it first, then split the Valgrind fix and other changes into focused PRs as suggested. |
|
@wenzeslaus The tests are added in PR #6981. I’d appreciate your review. |
Summary
This PR fixes memory safety issues in
r.geomorphonthat caused Valgrind to report“Conditional jump or move depends on uninitialised value(s)”, primarily for border and NULL cells.
Fixes #5770.
Problem (Before)
continue, skipping pattern computation.patternpointer, causing:Fix (After)
continuelogic with a clearif / elsestructure:patternis never dereferenced unless initialized.Verification
Notes
This PR does not change the geomorphon algorithm.
It strictly improves memory safety and robustness.