Skip to content

[v0.14.0] Array.h array subscript 1 is above array bounds of 'Attribute_Request_Callback<5> [1]' [-Werror=array-bounds=] #239

Description

@AdrienAdB

Hello, I have upgraded sdk to v0.14.0, I can successfully build when OTA apis isn't included.

Build is not possible when OTA instance is initialized:

// Initialize used apis
OTA_Firmware_Update ota;
const std::array<IAPI_Implementation*, 1U> apis =
{
    &ota
};

// Initialize ThingsBoard instance with the maximum needed buffer size
ThingsBoard tb(mqttClient, MAX_MESSAGE_SIZE, Default_Max_Stack_Size, apis);

Build error:

subscript 1 is above array bounds of 'Attribute_Request_Callback<5> [1]' [-Werror=array-bounds=]

I am able to build if I comment line 171 of Array.h
https://github.com/thingsboard/thingsboard-client-sdk/blob/master/src/Array.h#L171

Environment:

  • ESP-IDF 6.9.0
  • Platformio
  • Thingsboard sdk v0.14.0

Debug terminal

In member function 'void Array<T, Capacity>::erase(const InputIterator&) [with InputIterator = Attribute_Request_Callback<5>*; T = Attribute_Request_Callback<5>; unsigned int Capacity = 1]',
    inlined from 'static void Helper::remove(DataContainer&, const InputIterator&) [with DataContainer = Array<Attribute_Request_Callback<5>, 1>; InputIterator = Attribute_Request_Callback<5>*]' at .pio/libdeps/evisi-4-ntc/ThingsBoard/src/Helper.h:80:24,
    inlined from 'void Attribute_Request<MaxSubscriptions, MaxAttributes, Logger>::Process_Json_Response(const char*, const ArduinoJson::V6215HB2::JsonDocument&) [with unsigned int MaxSubscriptions = 1; unsigned int MaxAttributes = 5; Logger = DefaultLogger]' at .pio/libdeps/evisi-4-ntc/ThingsBoard/src/Attribute_Request.h:123:27:
.pio/libdeps/evisi-4-ntc/ThingsBoard/src/Array.h:171:43: error: array subscript 1 is above array bounds of 'Attribute_Request_Callback<5> [1]' [-Werror=array-bounds=]
  171 |                 m_elements[i] = m_elements[i + 1];
      |                                 ~~~~~~~~~~^
.pio/libdeps/evisi-4-ntc/ThingsBoard/src/Array.h: In member function 'void Attribute_Request<MaxSubscriptions, MaxAttributes, Logger>::Process_Json_Response(const char*, const ArduinoJson::V6215HB2::JsonDocument&) [with unsigned int MaxSubscriptions = 1; unsigned int MaxAttributes = 5; Logger = DefaultLogger]':
.pio/libdeps/evisi-4-ntc/ThingsBoard/src/Array.h:207:12: note: while referencing 'Array<Attribute_Request_Callback<5>, 1>::m_elements'
  207 |     T      m_elements[Capacity] = {}; // Underlying c-array holding our data

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions