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

pybricks.common.ble: fix compiler warning #291

Merged
merged 1 commit into from
Jan 19, 2025

Conversation

dlech
Copy link
Member

@dlech dlech commented Jan 19, 2025

With GCC 13 and -flto disabled, we were getting warnings like:

../../pybricks/common/pb_type_ble.c:291:21: error: array subscript 5 is outside the bounds of an interior zero-length array 'uint8_t[0]' {aka 'unsigned char[]'} [-Werror=zero-length-bounds]
291 |         value.v.data[5] = PB_BLE_BROADCAST_DATA_TYPE_SINGLE_OBJECT << 5;
    |         ~

Instead of using the zero-length array, access the d member directly. This allows the compiler to actually check for out of bounds access and warn us about it.

With GCC 13 and -flto disabled, we were getting warnings like:

    ../../pybricks/common/pb_type_ble.c:291:21: error: array subscript 5 is outside the bounds of an interior zero-length array 'uint8_t[0]' {aka 'unsigned char[]'} [-Werror=zero-length-bounds]
    291 |         value.v.data[5] = PB_BLE_BROADCAST_DATA_TYPE_SINGLE_OBJECT << 5;
        |         ~

Instead of using the zero-length array, access the d member directly.
This allows the compiler to actually check for out of bounds access
and warn us about it.
@dlech dlech merged commit 77384ec into pybricks:master Jan 19, 2025
15 checks passed
@dlech dlech deleted the fix-compiler-warning branch January 19, 2025 21:54
@coveralls
Copy link

Coverage Status

coverage: 56.36%. remained the same
when pulling a2c2653 on dlech:fix-compiler-warning
into 2284669 on pybricks:master.

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

Successfully merging this pull request may close these issues.

2 participants