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

Enum Value Out of Range Not Enforced at Runtime #2095

Open
Dominik-38 opened this issue Sep 24, 2024 · 2 comments
Open

Enum Value Out of Range Not Enforced at Runtime #2095

Dominik-38 opened this issue Sep 24, 2024 · 2 comments

Comments

@Dominik-38
Copy link

I encountered an issue with CycloneDDS where enum values outside the defined range are not enforced at runtime. Below is the IDL and the code snippet that demonstrates the problem (I used the HelloWorld example and modified it slightly):

IDL:

module SimpleEnum
{
    @bit_bound(32)
    enum MySimpleEnum
    {
        @value(5) A,
        @value(12345) B,
        @value(2) C
    };

    struct Data
    {
        long firstVal;
        long secondVal;
        MySimpleEnum e;
    };
};

Publisher Side:

SimpleEnum_Data msgEnum;
...
msgEnum.e = 38; // Assigning a value outside the defined enum range
...

The IDE (VS) correctly warns that the value 38 is out of range for MySimpleEnum. However, the code compiles and runs without any errors, and the publisher successfully publishes the value 38. I think this behavior is unwanted as it allows invalid enum values to be used, potentially leading to unexpected behavior in the application.

@dpotman
Copy link
Contributor

dpotman commented Sep 24, 2024

The current implementation for the enum type in the serializer only checks for the maximum value, which is a known limitation identified when adding extensions for enum support in #1149.

To add proper validation for enum values in the serializer, a list of allowed values would need to be included in the parameter list of the serializer VM opcode, taking into account that enum types can be appendable. Additional changes would also be necessary to handle cases where an enum is used within a (bounded) sequence, union, or array.

Extending the serializer for this is currently not planned, but any contributions toward this improvement would be highly appreciated!

@Dominik-38
Copy link
Author

Alright, thank you for your fast answer!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants