Boost C++ Libraries: Ticket #12174: Tokenizer delivers additional null byte - string token https://svn.boost.org/trac10/ticket/12174 <p> If I run the attached program I get </p> <p> TokenStartsHere:McStructuredLoanEngine::calculate() trace information:TokenEndsHere / length of string is 53 TokenStartsHere::<a class="missing wiki">TokenEndsHere</a> / length of string is 1 </p> <p> The first token is expected, but the second is not. I seems to contain one null byte. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/12174 Trac 1.4.3 Peter Caspers <pcaspers1973@…> Tue, 03 May 2016 10:29:38 GMT attachment set https://svn.boost.org/trac10/ticket/12174 https://svn.boost.org/trac10/ticket/12174 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">sep.cpp</span> </li> </ul> <p> minimal test program producing the bug </p> Ticket damian.meden@… Fri, 06 May 2016 22:25:10 GMT <link>https://svn.boost.org/trac10/ticket/12174#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12174#comment:1</guid> <description> <p> I just tried with several boost versions and I have the same issue but in my case all the streams you have in your example fails after getting out the string directly into the Container. </p> <p> a workaround would be: </p> <p> std::string str = tmp.str(); boost::tokenizer&lt;boost::char_separator&lt;char&gt; &gt; t(str, sep); </p> <p> then it will work. </p> <p> I've tested this with VS14, gcc4.8 and gcc4.9. </p> <p> I'll have a look at the implementation. </p> <p> Thanks. </p> </description> <category>Ticket</category> </item> <item> <author>damian.meden@…</author> <pubDate>Thu, 12 May 2016 13:42:39 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/12174#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12174#comment:2</guid> <description> <p> Hi, more data here: </p> <p> tokeniser holds an iterator to the beginning and the end of the container, ostringstream::str() will return a temporary container(in this case std::string) which will be deleted at the end of the expression where you are using it, meaning that the tokeniser will holds a iterator to a temporary object which was already destroyed, this is Undefined Behaviour, different compiler are doing different things. If you hold the temporal object in scope(string str=tmp.str()) meanwhile you tokenize it will fix the issue, that's the proper Idiom I would say. </p> <p> Also this is not related to the 'escaped' character \n, you can use any proper character there and will have the same results. </p> <p> Dam. </p> </description> <category>Ticket</category> </item> <item> <author>Peter Caspers <pcaspers1973@…></author> <pubDate>Fri, 13 May 2016 06:55:58 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/12174#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12174#comment:3</guid> <description> <p> Hi Dam, thanks a lot. It's clear now what is going on, and easy to avoid following your suggestion. Kind Regards, Peter </p> </description> <category>Ticket</category> </item> </channel> </rss>