Re: [Boost-bugs] [Boost C++ Libraries] #665: bug in char_separator

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #665: bug in char_separator
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2007-11-22 10:20:06


#665: bug in char_separator
----------------------+-----------------------------------------------------
  Reporter: araine | Owner: jbandela
      Type: Bugs | Status: closed
 Milestone: | Component: tokenizer
   Version: None | Severity: Problem
Resolution: invalid | Keywords:
----------------------+-----------------------------------------------------
Changes (by johnmaddock):

 * cc: araine_at_[hidden] (added)
  * status: assigned => closed
  * resolution: None => invalid

Old description:

> {{{
> tokens produced by boost::tokenizer have character
> replaced by space, the following code:
>
> typedef boost::tokenizer< boost::char_separator<char> >
> Tokenizer;
> boost::char_separator<char> sep("/");
> Tokenizer tok(std::string("Log/logging"), sep);
> for (Tokenizer::iterator t = tok.begin();
> t != tok.end(); ++t)
> {
> std::cout << "<" << *t << "> ";
> }
> std::cout << std::endl;
>
> produces this output:
> <Log> <log ing>
>
> instead:
> <Log> <logging>
> }}}

New description:

 {{{
 tokens produced by boost::tokenizer have character
 replaced by space, the following code:

 typedef boost::tokenizer< boost::char_separator<char> >
  Tokenizer;
 boost::char_separator<char> sep("/");
 Tokenizer tok(std::string("Log/logging"), sep);
 for (Tokenizer::iterator t = tok.begin();
     t != tok.end(); ++t)
 {
     std::cout << "<" << *t << "> ";
 }
 std::cout << std::endl;

 produces this output:
 <Log> <log ing>

 instead:
 <Log> <logging>
 }}}

Comment:

 There's a bug in your code: the string is passed as a temporary and is out
 of scope by the time it is referenced, consequently you are reading from
 invalid memory, with unpredictable results.

--
Ticket URL: <http://svn.boost.org/trac/boost/ticket/665#comment:2>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.


This archive was generated by hypermail 2.1.7 : 2017-02-16 18:49:57 UTC