Versions Compared

Key

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

The index operators

Code Block

const_reference operator[](size_type pos) const;
reference operator[](size_type pos);

...

Code Block
bgColor#FFcccc
langcpp

string bs("01234567");
size_t i = f();

bs[i] = '\0';

...

Code Block
bgColor#ccccff
langcpp

string bs("01234567");
try {
  size_t i = f();
  bs.at(i) = '\0';
}
catch (...) {
  cerr << "Index out of range" << endl;
}

...

Code Block
bgColor#FFcccc
langcpp

string bs("01234567");
for (int i=0; i < 100; i++) {
  bs[i] = '\0';
}

...

Code Block
bgColor#ccccff
langcpp

size_t const max_fill = 100;
std::string bs("01234567");

fill(bs.begin(), bs.begin()+std::min(max_fill, bs.length()), '\0' );

...

Rule

Severity

Likelihood

Remediation Cost

Priority

Level

STR39-CPP

high

likely

high

P9

L2

Automated Detection

Tool

Version

Checker

Description

 PRQA QA-C++

 
Include Page
PRQA QA-C++_v
PRQA QA-C++_v
-wc "::std::vector::[]" 

Bibliography

[Seacord 05] Chapter 2 Strings
[ISO/IEC 14882-2003] Section 21.3.4 basic_string element access

...