Don't silently convert integers to enum types #707

Open
opened 2026-03-11 17:11:55 -05:00 by gilles-peskine-arm · 0 comments
gilles-peskine-arm commented 2026-03-11 17:11:55 -05:00 (Migrated from github.com)

Our unit tests very often pass int to a test function, which it then uses as an enum type (mbedtls_md_type_t, mbedtls_cipher_type_t, etc.). This is correct C as long as the value is in the set of valid values for the enum type, but it makes some compilers cranky. For example IAR complains Pe188 "enumerated type mixed with another type".

The goal of this issue is to rewrite the unit tests to avoid this. The best approach is probably to first resolve https://github.com/Mbed-TLS/mbedtls/issues/4913, and then change the types of the test entry points to directly use the enum type instead of int. Note that this can only be done when the test data is valid: if the test data can also pass invalid values (which we do in some negative tests), then the test function should keep using int (or unsigned or other non-enum type), and then we should cast the value to the enum type if it's valid.

Definition of done: at least, IAR no longer emits Pe188 diagnostics. (Note that this isn't a complete definition of done if we only do the IAR build in a baremetal configuration, because some test code is omitted.)

Our unit tests very often pass `int` to a test function, which it then uses as an enum type (`mbedtls_md_type_t`, `mbedtls_cipher_type_t`, etc.). This is correct C as long as the value is in the set of valid values for the enum type, but it makes some compilers cranky. For example IAR complains Pe188 "enumerated type mixed with another type". The goal of this issue is to rewrite the unit tests to avoid this. The best approach is probably to first resolve https://github.com/Mbed-TLS/mbedtls/issues/4913, and then change the types of the test entry points to directly use the enum type instead of `int`. Note that this can only be done when the test data is valid: if the test data can also pass invalid values (which we do in some negative tests), then the test function should keep using `int` (or `unsigned` or other non-enum type), and then we should cast the value to the enum type if it's valid. Definition of done: at least, IAR no longer emits Pe188 diagnostics. (Note that this isn't a complete definition of done if we only do the IAR build in a baremetal configuration, because some test code is omitted.)
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-Mbed-TLS/TF-PSA-Crypto#707
No description provided.