Skip to content

Bug in CSRectGrid::IncreaseResolution #75

Description

@biergaizi

There exists a bug in CSRectGrid::IncreaseResolution, caught in -Wextra by clang: CSRectGrid.cpp:220:18: warning: overlapping comparisons always evaluate to false [-Wtautological-overlap-compare]

The source code reads:

void CSRectGrid::IncreaseResolution(int nu, int factor)
{
        if ((nu<0) || (nu>=GetDimension())) return;
        if ((factor<=1) && (factor>9)) return;
        // ......
}

This is clearly a bug, how can a number be less than 1 and greater than 9 at the same time? It's a logical impossibility, so this check has effectively been disabled for the project's history.

I want to change && to ||, but the question remains: it's logical to reject number less than 1, but why silently rejecting factors greater than 9. Does the code malfunction if the factor is greater than 9? I don't think so. If it's a bad decision by the user, the code should implement that bad decision rather than silently rejecting it. It's more suitable to print a warning message to stderr, or throw a C++ exception, or change the function signature to throw an error code.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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