Skip to content

r.horizon: Remove unreachable zero step branch in raster mode - #8148

Open
mallesh-bot wants to merge 1 commit into
OSGeo:mainfrom
mallesh-bot:r-horizon-dead-step-branch
Open

mallesh-bot wants to merge 1 commit into
OSGeo:mainfrom
mallesh-bot:r-horizon-dead-step-branch

Conversation

@mallesh-bot

Copy link
Copy Markdown
Contributor

Description

I removed the settings->step == 0.0 branch from calculate_raster_mode(), which called sprintf() on a NULL pointer. I also removed the settings->step != 0.0 check before G_generate_basename() because it was always true. These changes don't affect how the code works for users.

Motivation and context

The step value is already changed from 0 to 360 in main() before calculate_raster_mode() is called, so that branch could never actually run. GCC was still showing warnings because it couldn't detect that the branch was unreachable. Also, calculate_raster_mode() is part of r.horizon, not r.fill.stats.

Fixes #4472.

How has this been tested?

I checked the CI build with -Werror and ran the existing r.horizon tests, which passed. This includes test_raster_mode_one_direction, which runs raster mode without step. I haven't added a new test because the removed code was unreachable.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing
    functionality to not work as before)

Checklist

  • PR title provides summary of the changes and starts with one of the
    pre-defined prefixes
  • My code follows the code style
    of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.

main() replaces a zero step with 360 before calculate_raster_mode()
runs, so the step == 0 branch, which called sprintf() on a NULL
pointer, was never taken. GCC still warned about it with -Wnonnull
and -Wformat-overflow.

Fixes OSGeo#4472
@github-actions github-actions Bot added raster Related to raster data processing C Related code is in C module labels Nov 3, 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 module raster Related to raster data processing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] GCC nonnull and format-overflow in r.fill.stats

1 participant