[LLVMbugs] [Bug 16240] New: regex: regex_replace does not handle \b correctly

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Jun 6 02:41:59 PDT 2013


            Bug ID: 16240
           Summary: regex: regex_replace does not handle \b correctly
           Product: libc++
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
          Assignee: hhinnant at apple.com
          Reporter: buglibcxx at lancom.de
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Example from cplusplus.org reference:

  std::string s ("there is a subsequence in the string\n");
  std::regex e ("\\b(sub)([^ ]*)");   // matches words beginning by "sub"

  // using string/c-string (3) version:
  std::cout << std::regex_replace (s,e,"sub-$2");

Testing this with valgrind results in the message: "Invalid read of size 1"

This is because of setting match_prev_avail-flag in a case when we are at the
beginning of a string. This leads to a read operation one byte before the
beginning of the string in "__word_boundary<_CharT, _Traits>::__exec(__state&
__s) const"
The flag is set in "regex_iterator<BidirectionalIterator, _CharT,
_Traits>::operator++()" called from "regex_replace(_OutputIterator __out,
_BiderctionalIterator __first, _BiderctionalIterator __last, 
const basic_regex<_CharT, _Traits>& __e, const _CharT* __fmt,
regex_constants::match_flag_type __flags = regex::constants::match_default)"

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20130606/d3574c63/attachment.html>

More information about the llvm-bugs mailing list