Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter returns the wrong result with unsigned type values #3

Open
RonyK opened this issue Sep 9, 2021 · 0 comments
Open

Filter returns the wrong result with unsigned type values #3

RonyK opened this issue Sep 9, 2021 · 0 comments
Labels
bug Something isn't working

Comments

@RonyK
Copy link
Member

RonyK commented Sep 9, 2021

The filter operator has an error with unsigned values.
Current code casts any type of values to 'int64_t', and the derived type Ty_ is just ignored.

For example, here is the code from <parse/term.h>

template <typename Ty_>
bool evaluateEqual(const int64_t v1, const int64_t v2)
{
    return v1 == v2;
}

In this type-casting, an unsigned value might be converted to a negative value.
(e.g., unsigned char: 129 -> signed char: -127)
Accordingly, the relational operators (or comparison operators) misunderstand the value and work differently from our expectations.

The code should be changed, such as

template <typename TyLeft_, typename TyRight_>
bool evaluateEqual(const TyLeft_ v1, const TyRight_ v2)
{
    return v1 == v2;
}
@RonyK RonyK added the bug Something isn't working label Sep 9, 2021
@RonyK RonyK added this to the Core operators milestone Sep 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant