Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#3525 closed Bugs (fixed)

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@…

Description

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

Attachments (1)

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

Download all attachments as: .zip

Change History (5)

comment:1 by s.ochsenknecht@…, 13 years ago

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 ...

by s.ochsenknecht@…, 13 years ago

Attachment: patch_ticket3525.diff added

patch

comment:2 by Sascha Ochsenknecht <s.ochsenknecht@…>, 13 years ago

Cc: s.ochsenknecht@… added

comment:3 by Sascha Ochsenknecht, 13 years ago

Resolution: fixed
Status: newclosed

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

comment:4 by Sascha Ochsenknecht, 13 years ago

Milestone: Boost 1.41.0Boost 1.42.0
Note: See TracTickets for help on using tickets.