Skip to content

esp-idf 5.5.3 compatibility issue #397

@wuyuanyi135

Description

@wuyuanyi135

In 5.5.3 the compilation fails due to

C:/Users/wuyua/Project/UniLAB/projects/project_unilab_transport/managed_components/h2zero__esp-nimble-cpp/src/NimBLEDevice.cpp: In static member function 'static NimBLEAddress NimBLEDevice::getBondedAddress(int)':
C:/Users/wuyua/Project/UniLAB/projects/project_unilab_transport/managed_components/h2zero__esp-nimble-cpp/src/NimBLEDevice.cpp:685:37: error: array subscript 0 is outside array bounds of 'ble_addr_t [0]' [-Werror=array-bounds=]
  685 |     rc = ble_store_util_bonded_peers(&peer_id_addrs[0], &num_peers, MYNEWT_VAL(BLE_STORE_MAX_BONDS));
      |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:/Users/wuyua/Project/UniLAB/projects/project_unilab_transport/managed_components/h2zero__esp-nimble-cpp/src/NimBLEDevice.cpp:683:16: note: while referencing 'peer_id_addrs'
  683 |     ble_addr_t peer_id_addrs[MYNEWT_VAL(BLE_STORE_MAX_BONDS)];
      |                ^~~~~~~~~~~~~
C:/Users/wuyua/Project/UniLAB/projects/project_unilab_transport/managed_components/h2zero__esp-nimble-cpp/src/NimBLEDevice.cpp:690:46: error: array subscript index is outside array bounds of 'ble_addr_t [0]' [-Werror=array-bounds=]
  690 |     return NimBLEAddress(peer_id_addrs[index]);
      |                                              ^
C:/Users/wuyua/Project/UniLAB/projects/project_unilab_transport/managed_components/h2zero__esp-nimble-cpp/src/NimBLEDevice.cpp:683:16: note: while referencing 'peer_id_addrs'
  683 |     ble_addr_t peer_id_addrs[MYNEWT_VAL(BLE_STORE_MAX_BONDS)];
      |                ^~~~~~~~~~~~~

simple fix was to add

idf_component_get_property(nimble_lib h2zero__esp-nimble-cpp COMPONENT_LIB)

if(nimble_lib AND IDF_VERSION_MAJOR EQUAL 5 AND IDF_VERSION_MINOR EQUAL 5 AND IDF_VERSION_PATCH EQUAL 3)
    message("Detected ESP-IDF 5.5.3: Applying array-bounds fix for NimBLE")
    target_compile_options(${nimble_lib} PRIVATE "-Wno-error=array-bounds")
endif()

after project statement, such as


include($ENV{IDF_PATH}/tools/cmake/project.cmake)
idf_build_set_property(MINIMAL_BUILD ON)
project(aaaaa)

idf_component_get_property(nimble_lib h2zero__esp-nimble-cpp COMPONENT_LIB)

if(nimble_lib AND IDF_VERSION_MAJOR EQUAL 5 AND IDF_VERSION_MINOR EQUAL 5 AND IDF_VERSION_PATCH EQUAL 3)
    message("Detected ESP-IDF 5.5.3: Applying array-bounds fix for NimBLE")
    target_compile_options(${nimble_lib} PRIVATE "-Wno-error=array-bounds")
endif()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions