Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Edited by NavBot (jp)

...

Code Block
bgColor#FFcccc
char input[] = ""bogus@addr.com; cat /etc/passwd"";
string email;
string::iterator loc = email.begin();

// copy into string converting ";"";" to " "" "
for (size_t i=0; i <&lt;= strlen(input); i++) {
  if (input[i] != ';') {
    email.insert(loc++, input[i]);
  }
  else {
    email.insert(loc++, ' ');
  }
} // end string for each element in NTBS

...

Code Block
bgColor#ccccff
char input[] = "&quot;bogus@addr.com; cat /etc/passwd"&quot;;
string email;
string::iterator loc = email.begin();

// copy into string converting ";"&quot;;&quot; to " "&quot; &quot;
for (size_t i=0; i <&lt;= strlen(input); i++) {
  if (input[i] != ';') {
    loc = email.insert(loc, input[i]);
  }
  else {
    loc = email.insert(loc, ' ');
  }
  ++loc;
} // end string for each element in NTBS

...

Code Block
bgColor#FFcccc
string s("rcs"&quot;rcs&quot;);
string::iterator si = s.begin();

for (size_t i=0; i<20i&lt;20; ++i) {
  s.push_back('x');
}
s.insert(si, '*');

...

Code Block
bgColor#ccccff
string s("rcs"&quot;rcs&quot;);
string::iterator si = s.begin();

for (size_t i=0; i <&lt; 20; ++i) {
   if ( s.size() == s.capacity() ) {
     break;
   }
  s.push_back('x');
}
s.insert(si, '*');

...

Wiki Markup
\[[Meyers 01|AA. C++ References#Meyers 01]\] Item 43: Prefer algorithm calls to hand-written loops.
\[[ISO/IEC 14882-2003|AA. C++ References#ISO/IEC 14882-2003]\] 21.3 Class template basic_string.

...

BSC32-C. Do not use the pointer value returned by c_str() after any subsequent call to a non-const member function      07. Characters and Strings (STR)      08. Memory Management (MEM)