Skip to content

Scan server: Enforce loop limits#3795

Merged
kasemir merged 1 commit intomasterfrom
scan_loop_limits
Apr 29, 2026
Merged

Scan server: Enforce loop limits#3795
kasemir merged 1 commit intomasterfrom
scan_loop_limits

Conversation

@kasemir
Copy link
Copy Markdown
Collaborator

@kasemir kasemir commented Apr 29, 2026

Fixes #3794

The scan server loop command started out as basically
for (double value=start; value<=end; value += step).
While this is quite a normal loop, with equivalent loops available in every programming language, there can be subtle rounding errors. A loop from 0 to 10.0 for example might end at 9.9999 instead of exactly 1.0, with details depending on the step size.
In PR #3305, commits 30964db and 0e2df3a tried to make it more predictable by avoiding rounding errors. Unfortunately, this disregarded the loop end points. A loop from 1.0 to '2.0' in steps of 2.0 would now yield values 1.0 and 3.0, with the latter clearly being beyond the loop end of 2.0.

A basic for (double value=1.0; value<=2.0; value += 2.0) loop would only give a value of 1.0 and then end because the next potential value of 1.0+2.0=3.0 is beyond the loop end condition.
I could argue that this original loop command behavior was good and didn't need to be "fixed" in the first place, but in keeping with the spirit of 0e2df3a to include the bounds, this update will will enforce the loop limits, resulting in a loop with values 1.0 and 2.0.

Checklist

  • Testing:
    • The feature has automated tests
    • Tests were run

@sonarqubecloud
Copy link
Copy Markdown

@shroffk
Copy link
Copy Markdown
Member

shroffk commented Apr 29, 2026

The computeStop seems like a reliable way to address the multitude of cases... and thank you for the unit tests.

@kasemir kasemir merged commit 0908162 into master Apr 29, 2026
5 checks passed
@kasemir kasemir deleted the scan_loop_limits branch April 29, 2026 17:30
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.

Scan loop command exceeds end value

2 participants