sonar-openedge icon indicating copy to clipboard operation
sonar-openedge copied to clipboard

Conversion can overflow with enums creates a lot of non issues

Open movedoa opened this issue 3 years ago • 4 comments

A lot of the issues we have with the conversion overflow rule come from enums where we save the value as int.

INTEGER(FooEnum:GetValue())

I guess in 99% of cases, enums don't have more than 2^32 values. If the enum has not more than 2^32 values, the rule should not create an issue.

movedoa avatar Dec 01 '21 13:12 movedoa

The enum doesn't need to have more than 2^32 values, it just needs one member with a large value in its definition:

ENUM Direction:
    DEFINE ENUM North = 8000000000
                South
                East
                West.
END ENUM.

Why save as INTEGER(FooEnum:GetValue()) and not directly as FooEnum:GetValue() ?

gquerret avatar Dec 01 '21 14:12 gquerret

You are correct, i didn't think about that.

movedoa avatar Dec 01 '21 15:12 movedoa

Ok i want to reopen this, at least in our codebase, most enums don't have values that would overflow integer. Would it be possible to only flag enums that have values > int?

movedoa avatar May 13 '22 11:05 movedoa

ENUM values are now read from rcode (only in v12, that won't work with v11 rcode). Rule will be modified later (so not for tomorrow's release).

gquerret avatar Sep 08 '22 16:09 gquerret

This is still a huge source for false positives but i would rather not disable the rule since the LONGCHAR/STRING checks are very nice to have. Is there a chance for this to make one of the next version?

movedoa avatar Dec 05 '23 09:12 movedoa

Found a clean way to implement that (which required some changes introduced recently). That will be fixed in next version.

gquerret avatar Dec 07 '23 17:12 gquerret

Available in 2.24

gquerret avatar Dec 11 '23 07:12 gquerret