Skip to content

warn on enum conversions #18430

Closed
Closed
@arnetheduck

Description

@arnetheduck

Converting an integer to enum is fraught with issues - often the integer is coming from an untrusted source such as a file or the network and in code reviews, we've found many instances where it leads to remote exploits crashing the application or worse.

The safe way to convert an enum is to use a case statement, converting each enum value to an integer and making a comparison - a macro can be used to generate this list (see https://forum.nim-lang.org/t/8188).

The most reasonable thing for most code out there is to avoid the MyEnum(anInteger) conversion entirely - since it can't be changed to behave safely, a compile-time warning is appropriate, educating users about the issues with the construct.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions