Opened 12 years ago

Closed 12 years ago

#4286 closed Bugs (invalid)

regex - making a pointer to an invalid dereferenced iterator.

Reported by: CharlesPenny@… Owned by: John Maddock
Milestone: Boost 1.43.0 Component: regex
Version: Boost 1.44.0 Severity: Problem
Keywords: Cc:

Description

in function w32_transform in libs/regex/src/w32_regex_traits.cpp

LCMapStringA() is called with parameter &*result.begin()

In this case the std::string is created with std::string result(++bytes, '\0'), so I would have thought that *result.begin() would return result.end() as the length of the string is zero, even though a chunk of memory has been allocated.

In my case, the iterator returns 0xccccccc and the subsequent LCMapStringA() call fails spectacularly in debug mode.

I have _HAS_ITERATOR_DEBUGGING and _SECURE_SCL turned off.

I switched to using &(result[0]) instead and that was fine.

Change History (3)

comment:1 by John Maddock, 12 years ago

The code should be correct: it creates a string that is ++bytes long and consists entirely of the null character. So begin() != end().

I can't reproduce this here, can you let me have a self contained test case?

Also can you check that you're not mixing different values for _HAS_ITERATOR_DEBUGGING and _SECURE_SCL in different translation units (for example in your source and the regex lib). Doing this will cause strange failures like this to occur.

HTH, John.

comment:2 by CharlesPenny@…, 12 years ago

I am mixing different values for _HAS_ITERATOR_DEBUGGING and _SECURE_SCL in different translation units (which is the basic problem). I think my code change is working as it is avoiding the use of iterators.

comment:3 by Steven Watanabe, 12 years ago

Resolution: invalid
Status: newclosed
Note: See TracTickets for help on using tickets.