23.03.2017 Views

SEI CERT C++ Coding Standard

sei-cert-cpp-coding-standard-2016-v01

sei-cert-cpp-coding-standard-2016-v01

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

3.9 EXP58-CPP. Pass an object of the correct type to va_start 126<br />

3.10 EXP59-CPP. Use offsetof() on valid types and members 130<br />

3.11 EXP60-CPP. Do not pass a nonstandard-layout type object across execution<br />

boundaries 134<br />

3.12 EXP61-CPP. A lambda object must not outlive any of its reference captured objects 139<br />

3.13 EXP62-CPP. Do not access the bits of an object representation that are not part<br />

of the object’s value representation 142<br />

3.14 EXP63-CPP. Do not rely on the value of a moved-from object 147<br />

4 Integers (INT) 153<br />

4.1 INT50-CPP. Do not cast to an out-of-range enumeration value 153<br />

5 Containers (CTR) 157<br />

5.1 CTR50-CPP. Guarantee that container indices and iterators are within the valid range 157<br />

5.2 CTR51-CPP. Use valid references, pointers, and iterators to reference elements of a<br />

container 163<br />

5.3 CTR52-CPP. Guarantee that library functions do not overflow 170<br />

5.4 CTR53-CPP. Use valid iterator ranges 174<br />

5.5 CTR54-CPP. Do not subtract iterators that do not refer to the same container 177<br />

5.6 CTR55-CPP. Do not use an additive operator on an iterator if the result would overflow 182<br />

5.7 CTR56-CPP. Do not use pointer arithmetic on polymorphic objects 184<br />

5.8 CTR57-CPP. Provide a valid ordering predicate 189<br />

5.9 CTR58-CPP. Predicate function objects should not be mutable 193<br />

6 Characters and Strings (STR) 198<br />

6.1 STR50-CPP. Guarantee that storage for strings has sufficient space for character<br />

data and the null terminator 198<br />

6.2 STR51-CPP. Do not attempt to create a std::string from a null pointer 201<br />

6.3 STR52-CPP. Use valid references, pointers, and iterators to reference elements of a<br />

basic_string 205<br />

6.4 STR53-CPP. Range check element access 209<br />

7 Memory Management (MEM) 213<br />

7.1 MEM50-CPP. Do not access freed memory 213<br />

7.2 MEM51-CPP. Properly deallocate dynamically allocated resources 220<br />

7.3 MEM52-CPP. Detect and handle memory allocation errors 233<br />

7.4 MEM53-CPP. Explicitly construct and destruct objects when manually managing<br />

object lifetime 238<br />

7.5 MEM54-CPP. Provide placement new with properly aligned pointers to sufficient<br />

storage capacity 243<br />

7.6 MEM55-CPP. Honor replacement dynamic storage management requirements 249<br />

7.7 MEM56-CPP. Do not store an already-owned pointer value in an unrelated smart<br />

pointer 253<br />

7.8 MEM57-CPP. Avoid using default operator new for over-aligned types 258<br />

<strong>SEI</strong> <strong>CERT</strong> <strong>C++</strong> CODING STANDARD (2016 EDITION) | V01<br />

Software Engineering Institute | Carnegie Mellon University<br />

[DISTRIBUTION STATEMENT A] Approved for public release and unlimited distribution.<br />

ii

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!