Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

In this compliant solution, access to the vector is accomplished with the at() method. This method provides bounds checking, throwing an out_of_range exception if pos is not a valid index value. The insert_in_table() function is declared with noexcept(false) in compliance with ERR30-CPP. Try to recover gracefully from unexpected errorsDo not call std::terminate(), std::abort(), or std::_Exit().

Code Block
bgColor#ccccff
langcpp
#include <vector>
 
void insert_in_table(std::vector<int> &table, std::size_t pos, int value) noexcept(false) {
  table.at(pos) = value;
}

...

[ISO/IEC 14882-2014]

23, "Containers Library"
24.2.1, "In General" 

[Viega 05]Section 5.2.13, "Unchecked Array Indexing"
[ISO/IEC PDTR 24772]"XYX Boundary Beginning Violation," "XYY Wrap-around Error," and "XYZ Unchecked Array Indexing"

 

...

CTR04-CPP. Assume responsibility for cleaning up data referenced by a container of pointers      006. Containers (CTR)      Image Added Image Added Image Modified