Skip to content

data range overflow cause infinite loop #1

Description

@MoreGames

While testing your algorithm and implementation on a middle large area, I noticed a problem in line

if (rightBound <= right) break; // right < rightBound

(line numer 422) in file LineOfSightScanner.cpp

In the underlying comparison

return o.d*n > o.n*d;

of the Fraction objects, the data range of int is easily exceeded, which can lead to negative numbers where there should be positive ones, which can lead to a comparison result of false instead of true, which can lead to an infinite loop.

I changed n and d of the Fraction class to long long for a simple solution to the problem (ignoring some implicit casts with potential data loss); for sure not the best way.

Maybe you can update your implementation for these cases.

Great work, easy to use, extensive description!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions