@@ -560,6 +560,7 @@ namespace etl
560560 // *********************************************************************
561561 reference operator [](size_type i)
562562 {
563+ ETL_ASSERT_CHECK_INDEX_OPERATOR (i < size (), ETL_ERROR (string_out_of_bounds));
563564 return p_buffer[i];
564565 }
565566
@@ -570,6 +571,7 @@ namespace etl
570571 // *********************************************************************
571572 const_reference operator [](size_type i) const
572573 {
574+ ETL_ASSERT_CHECK_INDEX_OPERATOR (i < size (), ETL_ERROR (string_out_of_bounds));
573575 return p_buffer[i];
574576 }
575577
@@ -603,6 +605,7 @@ namespace etl
603605 // *********************************************************************
604606 reference front ()
605607 {
608+ ETL_ASSERT_CHECK_EXTRA (size () > 0 , ETL_ERROR (string_out_of_bounds));
606609 return p_buffer[0 ];
607610 }
608611
@@ -612,6 +615,7 @@ namespace etl
612615 // *********************************************************************
613616 const_reference front () const
614617 {
618+ ETL_ASSERT_CHECK_EXTRA (size () > 0 , ETL_ERROR (string_out_of_bounds));
615619 return p_buffer[0 ];
616620 }
617621
@@ -621,7 +625,8 @@ namespace etl
621625 // *********************************************************************
622626 reference back ()
623627 {
624- return p_buffer[current_size - 1 ];
628+ ETL_ASSERT_CHECK_EXTRA (size () > 0 , ETL_ERROR (string_out_of_bounds));
629+ return p_buffer[size () - 1 ];
625630 }
626631
627632 // *********************************************************************
@@ -630,7 +635,8 @@ namespace etl
630635 // *********************************************************************
631636 const_reference back () const
632637 {
633- return p_buffer[current_size - 1 ];
638+ ETL_ASSERT_CHECK_EXTRA (size () > 0 , ETL_ERROR (string_out_of_bounds));
639+ return p_buffer[size () - 1 ];
634640 }
635641
636642 // *********************************************************************
@@ -764,7 +770,7 @@ namespace etl
764770 set_truncated (n > CAPACITY);
765771
766772#if ETL_HAS_ERROR_ON_STRING_TRUNCATION
767- ETL_ASSERT (is_truncated == false , ETL_ERROR (string_truncation));
773+ ETL_ASSERT (is_truncated () == false , ETL_ERROR (string_truncation));
768774#endif
769775#endif
770776
@@ -912,7 +918,7 @@ namespace etl
912918 set_truncated (n > free_space);
913919
914920#if ETL_HAS_ERROR_ON_STRING_TRUNCATION
915- ETL_ASSERT (is_truncated == false , ETL_ERROR (string_truncation));
921+ ETL_ASSERT (is_truncated () == false , ETL_ERROR (string_truncation));
916922#endif
917923#endif
918924
@@ -932,6 +938,8 @@ namespace etl
932938 // *********************************************************************
933939 iterator insert (const_iterator position, T value)
934940 {
941+ ETL_ASSERT_CHECK_EXTRA (cbegin () <= position && position <= cend (), ETL_ERROR (string_out_of_bounds));
942+
935943 // Quick hack, as iterators are pointers.
936944 iterator insert_position = to_iterator (position);
937945
@@ -984,6 +992,8 @@ namespace etl
984992 // *********************************************************************
985993 iterator insert (const_iterator position, size_type n, T value)
986994 {
995+ ETL_ASSERT_CHECK_EXTRA (cbegin () <= position && position <= cend (), ETL_ERROR (string_out_of_bounds));
996+
987997 iterator position_ = to_iterator (position);
988998
989999 if (n == 0 )
@@ -1071,6 +1081,9 @@ namespace etl
10711081 template <typename TIterator>
10721082 iterator insert (const_iterator position, TIterator first, TIterator last)
10731083 {
1084+ ETL_ASSERT_CHECK_EXTRA (cbegin () <= position && position <= cend (), ETL_ERROR (string_out_of_bounds));
1085+ ETL_ASSERT_CHECK_EXTRA (first <= last, ETL_ERROR (string_iterator));
1086+
10741087 iterator position_ = to_iterator (position);
10751088
10761089 if (first == last)
@@ -1307,6 +1320,8 @@ namespace etl
13071320 // *********************************************************************
13081321 etl::ibasic_string<T>& erase (size_type position, size_type length_ = npos)
13091322 {
1323+ ETL_ASSERT_CHECK_EXTRA (position <= size (), ETL_ERROR (string_out_of_bounds));
1324+
13101325 // Limit the length.
13111326 length_ = etl::min (length_, size () - position);
13121327
@@ -1322,6 +1337,8 @@ namespace etl
13221337 // *********************************************************************
13231338 iterator erase (iterator i_element)
13241339 {
1340+ ETL_ASSERT_CHECK_EXTRA (cbegin () <= i_element && i_element < cend (), ETL_ERROR (string_out_of_bounds));
1341+
13251342 etl::mem_move (i_element + 1 , end (), i_element);
13261343 p_buffer[--current_size] = 0 ;
13271344
@@ -1335,6 +1352,8 @@ namespace etl
13351352 // *********************************************************************
13361353 iterator erase (const_iterator i_element)
13371354 {
1355+ ETL_ASSERT_CHECK_EXTRA (cbegin () <= i_element && i_element < cend (), ETL_ERROR (string_out_of_bounds));
1356+
13381357 iterator i_element_ (to_iterator (i_element));
13391358
13401359 etl::mem_move (i_element + 1 , end (), i_element_);
@@ -1353,6 +1372,8 @@ namespace etl
13531372 // *********************************************************************
13541373 iterator erase (const_iterator first, const_iterator last)
13551374 {
1375+ ETL_ASSERT_CHECK_EXTRA (cbegin () <= first && first <= last && last <= cend (), ETL_ERROR (string_out_of_bounds));
1376+
13561377 iterator first_ = to_iterator (first);
13571378 iterator last_ = to_iterator (last);
13581379
@@ -2753,15 +2774,19 @@ namespace etl
27532774 set_truncated ((count > free_space) || this ->is_truncated () || truncated);
27542775
27552776#if ETL_HAS_ERROR_ON_STRING_TRUNCATION
2756- ETL_ASSERT (is_truncated == false , ETL_ERROR (string_truncation));
2777+ ETL_ASSERT (is_truncated () == false , ETL_ERROR (string_truncation));
27572778#endif
2779+ #else
2780+ (void )truncated;
27582781#endif
27592782
27602783#if ETL_HAS_STRING_CLEAR_AFTER_USE
27612784 if (secure)
27622785 {
27632786 set_secure ();
27642787 }
2788+ #else
2789+ (void )secure;
27652790#endif
27662791
27672792 // Limit the actual distance to the capacity.
@@ -2799,15 +2824,19 @@ namespace etl
27992824#if ETL_HAS_STRING_TRUNCATION_CHECKS
28002825 set_truncated (truncated);
28012826#if ETL_HAS_ERROR_ON_STRING_TRUNCATION
2802- ETL_ASSERT (is_truncated == false , ETL_ERROR (string_truncation));
2827+ ETL_ASSERT (is_truncated () == false , ETL_ERROR (string_truncation));
28032828#endif
2829+ #else
2830+ (void )truncated;
28042831#endif
28052832
28062833#if ETL_HAS_STRING_CLEAR_AFTER_USE
28072834 if (secure)
28082835 {
28092836 set_secure ();
28102837 }
2838+ #else
2839+ (void )secure;
28112840#endif
28122841
28132842 cleanup ();
0 commit comments