Skip to content

Commit 77384ec

Browse files
committed
pybricks.common.ble: fix compiler warning
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.
1 parent 2284669 commit 77384ec

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

pybricks/common/pb_type_ble.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ static mp_obj_t pb_module_ble_broadcast(size_t n_args, const mp_obj_t *pos_args,
288288
mp_obj_get_array(data_in, &n_objs, &objs);
289289
} else {
290290
// Set first type to indicate single object.
291-
value.v.data[5] = PB_BLE_BROADCAST_DATA_TYPE_SINGLE_OBJECT << 5;
291+
value.d[5] = PB_BLE_BROADCAST_DATA_TYPE_SINGLE_OBJECT << 5;
292292
// The one and only value is included directly after.
293293
index = 1;
294294
n_objs = 1;
@@ -297,14 +297,14 @@ static mp_obj_t pb_module_ble_broadcast(size_t n_args, const mp_obj_t *pos_args,
297297

298298
// Encode all objects.
299299
for (size_t i = 0; i < n_objs; i++) {
300-
index = pb_module_ble_encode(&value.v.data[5], index, objs[i]);
300+
index = pb_module_ble_encode(&value.d[5], index, objs[i]);
301301
}
302302

303303
value.v.size = index + 5;
304-
value.v.data[0] = index + 4; // length
305-
value.v.data[1] = MFG_SPECIFIC;
306-
pbio_set_uint16_le(&value.v.data[2], LEGO_CID);
307-
value.v.data[4] = mp_obj_get_int(self->broadcast_channel);
304+
value.d[0] = index + 4; // length
305+
value.d[1] = MFG_SPECIFIC;
306+
pbio_set_uint16_le(&value.d[2], LEGO_CID);
307+
value.d[4] = mp_obj_get_int(self->broadcast_channel);
308308

309309
pbdrv_bluetooth_start_broadcasting(&broadcast_task, &value.v);
310310
return pb_module_tools_pbio_task_wait_or_await(&broadcast_task);

0 commit comments

Comments
 (0)