Skip to content

raster: Fix three single-alert CodeQL findings - #7702

Merged
echoix merged 1 commit into
OSGeo:mainfrom
cwhite911:raster-codeql-singletons
Jul 15, 2026
Merged

echoix merged 1 commit into
OSGeo:mainfrom
cwhite911:raster-codeql-singletons

Conversation

@cwhite911

Copy link
Copy Markdown
Contributor

Fixes three single-alert CodeQL code scanning findings, one per tool:

  • r.watershed (ram/init_vars.c, cpp/incorrectly-checked-scanf, error severity): sscanf(ril_name, "%lf", &ril_value) == 0 misses the EOF (-1) return. Changed to != 1, which is also exactly what the seg variant (seg/init_vars.c) already does on the same line.
  • r.viewshed (grass.cpp, cpp/comparison-with-wider-type): the inner column loop counter j is dimensionType (unsigned short) but was compared against int Rast_window_cols(). Now bounded by the existing local ncols cast to dimensionType, matching the row loop one line above. The comparison is safe in practice because of the maxDimension guard, but the loop now mirrors the row loop and avoids the repeated function call.
  • r.in.gdal (main.c, cpp/redundant-null-check-simple, error severity): sdsdesc is unconditionally assigned a non-null pointer before the if (sdsdesc && *sdsdesc) check, so the null test is dead code; dropped it.

All three tools compile and their testsuites pass locally against nc_spm (r.watershed, r.viewshed, and r.in.gdal's 12 tests).

This is part of a larger effort to work through the open code scanning alerts, grouped into small PRs by issue type.

Written with the assistance of Claude Code.

r.watershed (ram): checking sscanf against 0 misses the EOF return, so
use != 1 as the seg variant already does. r.viewshed: bound the inner
column loop by the local int ncols cast to dimensionType, matching the
row loop, instead of comparing the unsigned short counter directly to
Rast_window_cols(). r.in.gdal: drop the null check on sdsdesc, which
is always assigned a non-null pointer beforehand.
@github-actions github-actions Bot added raster Related to raster data processing C Related code is in C C++ Related code is in C++ module labels Jul 14, 2026
Comment thread raster/r.watershed/ram/init_vars.c Resolved

@echoix echoix left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I can’t comment on the two other files, but for the sscanf, it is the correct fix, and the only one I actually dug in a bit this week.

@echoix
echoix merged commit e50e16c into OSGeo:main Jul 15, 2026
26 checks passed
@github-actions github-actions Bot added this to the 8.6.0 milestone Jul 15, 2026
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 C++ Related code is in C++ module raster Related to raster data processing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants