Corrupted boost::regex::smatch results (on MSVS 2003)
All, I'm using Boost.Regex from v1.35.0. We're seeing the smatch matchresults object getting corrupted when being returned by value from a function. The smatch variable is good within the function (it is an object defined locally on the stack), but when returned it is corrupted with bad data. We're seeing this only in Visual Studio 2003, and no other platform. I'm still trying to figure out a workaround, but I do not have source access at the moment, to try and debug it that way. Just wondering if there are any known issues. A google search didn't return much by way of discussion of this sort of issue. Thanks --dw
I'm using Boost.Regex from v1.35.0. We're seeing the smatch matchresults object getting corrupted when being returned by value from a function. The smatch variable is good within the function (it is an object defined locally on the stack), but when returned it is corrupted with bad data.
What do you mean by bad data? Is it simply that the iterators have been invalidated because the string that was matched no longer exists? HTH, John.
That's exactly what was happening. I pondered over what you wrote for about 24 hours, and it just "clicked" while brushing my teeth. I suppose the part that clicked, was the unspoken bit. I.E.: the match_results object is tied directly to the string you are operating on. We had something like: Boost::regex::smatch matchString(std::string str) { boost::regex::smatch retValue; // assign retValue by using boost::regex // doesn't work, and I don't care to look up syntax :) // retValue = regex.match(str); return retValue; } I didn't realize that the smatch required the string to remain in scope for it to be considered valid. I just checked the documentation quickly, and I actually didn't see this mentioned *anywhere*. Was I blind, and just missed it? Anyway, passing str as a const reference solved the problem, and we're happy again. My guess is that windows was invalidating the memory as soon as str went out of scope, rendering the data "bad". Opposed to our Linux build, where the data was still in memory (invalid, but still present), so we were able to still limp along. Yay for multi-platforms and boost::test :) Thanks for the inspiration/fix --dw -----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of John Maddock Sent: Saturday, April 11, 2009 3:37 AM To: boost-users@lists.boost.org Subject: Re: [Boost-users] Corrupted boost::regex::smatch results (on MSVS2003)
I'm using Boost.Regex from v1.35.0. We're seeing the smatch matchresults object getting corrupted when being returned by value from
a function. The smatch variable is good within the function (it is an object defined locally on the stack), but when returned it is corrupted
with bad data.
What do you mean by bad data? Is it simply that the iterators have been invalidated because the string that was matched no longer exists? HTH, John. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
I didn't realize that the smatch required the string to remain in scope for it to be considered valid. I just checked the documentation quickly, and I actually didn't see this mentioned *anywhere*. Was I blind, and just missed it?
Possibly not, I'll try and update the docs. John.
participants (2)
-
david.weber@l-3com.com
-
John Maddock