...
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 | ||||
---|---|---|---|---|
| ||||
#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" |
[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)