Repository navigation
r.coin: Fail when r.stats returns no data - #7841
Merged
Merged
Conversation
With no records parsed from r.stats, the category lists were allocated with a length of zero, collapse() counted from one and reported a single category anyway, and that category's value was read from the zero length allocation. r.coin printed a normal looking report for a category 0 and exited successfully, so a failure of r.stats looked like a valid result. Treat zero records as an error, which also removes the read from the zero length allocation. Fixes OSGeo#7734
echoix
approved these changes
Aug 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #7734.
When
r.statsproduces no output,make_coin()parsed zero records and nothing noticed:G_calloc(0, ...)collapse()starts its counter at 1, so an empty list still reports one categoryThe result was a normal looking coincidence report for a single category 0, with
EXIT_SUCCESS. A failure ofr.statswas indistinguishable from a valid result, which is how it went unnoticed in the OSGeo4W CI in #7732.Treating zero records as an error also removes the read from the zero length allocation.
I have not done the second improvement suggested in the issue, checking the child's exit status, because
G_popen_close()discards it and that is alib/gischange.Reproducing it
Two maps of only NULL cells are enough, since
r.coinrunsr.statswith the flag that skips the no data value, so nothing is printed:Before, that prints a full report with
cat# 0and all zeros, and exits 0. After, it exits 1 withERROR: No data returned from r.stats.Tests
test_r_coin_errors_without_datain the existingraster/r.coin/tests/test_coin.pydoes exactly the above and expects the module to fail. Checked against the unfixed build, where it fails withDID NOT RAISE CalledModuleError; the existingtest_r_coinpasses either way.clang-formatandruffreport no changes.I used an AI assistant while preparing this. I understand the change and can explain it.