Skip to content

Commit 95fc284

Browse files
committed
Span: add boundary check in subscript operator for debug profile
1 parent f6dd5ea commit 95fc284

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

platform/Span.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ struct Span {
183183
*/
184184
reference operator[](index_type index) const
185185
{
186+
#ifdef MBED_DEBUG
187+
MBED_ASSERT(0 <= index && index < Extent);
188+
#endif
186189
return _data[index];
187190
}
188191

@@ -454,6 +457,9 @@ struct Span<ElementType, SPAN_DYNAMIC_EXTENT> {
454457
*/
455458
reference operator[](index_type index) const
456459
{
460+
#ifdef MBED_DEBUG
461+
MBED_ASSERT(0 <= index && index < _size);
462+
#endif
457463
return _data[index];
458464
}
459465

0 commit comments

Comments
 (0)