Ticket #3525 (closed Bugs: fixed)

Opened 8 years ago

Last modified 7 years ago

problem with example response_file.cpp

Reported by: gvacanti@… Owned by: vladimir_prus
Milestone: Boost 1.42.0 Component: program_options
Version: Boost 1.40.0 Severity: Cosmetic
Keywords: Cc: s.ochsenknecht@…


The example works as advertised when the provided response file is used. If I modify the response file as follows:

-I bar1234567890123456789012345678901234567890 -I biz --magic=10

then the output is garbled:

Include paths: bar12�\pA5678Abar12

I can fix the problem if I add

string sss= ss.str();

and replace the tokenizer line with

tokenizer<char_separator<char> > tok(sss, sep);

I'm not too sure why the problem occurs, as ss.str() is supposed to return a copy.

I work on Linux, gcc (Ubuntu 4.3.3-5ubuntu4) 4.3.3


patch_ticket3525.diff (1.1 KB) - added by s.ochsenknecht@… 8 years ago.

Change History

comment:1 Changed 8 years ago by s.ochsenknecht@…

valgrind shows the errors.

stringstream::str() returns a *copy* of the string. This is a temporary object. The tokenizer does further operations on the string which is descruted already. The string has to live as long as the tokenizer.

So, its not a bug of program_options. I think the testcase has to be adapted. I will attach a patch soon ...

Changed 8 years ago by s.ochsenknecht@…


comment:2 Changed 7 years ago by Sascha Ochsenknecht <s.ochsenknecht@…>

  • Cc s.ochsenknecht@… added

comment:3 Changed 7 years ago by s_ochsenknecht

  • Status changed from new to closed
  • Resolution set to fixed

(In [57808]) correct usage of tokenizer, memory bug, Fixes #3525

comment:4 Changed 7 years ago by s_ochsenknecht

  • Milestone changed from Boost 1.41.0 to Boost 1.42.0

Add a comment

Modify Ticket

Change Properties
<Author field>
as closed
The resolution will be deleted. Next status will be 'reopened'

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.