Opened 11 years ago

Closed 8 years ago

Last modified 16 months ago

#773 closed Bugs (fixed)

program_options find assert fails with multibyte characters

Reported by: nobody Owned by: Vladimir Prus
Milestone: Component: program_options
Version: None Severity: Problem
Keywords: Cc:


I have experienced the following error when running my

Assertion failed: n == name.size()-2, file
line 118

It is compiled in VC++ 2005.  Using the debugger I was
able to determine that std::find was returning double
the expected value for the position of the comma.  So
for the option:


find set n = 8, instead of 4.

I am using multibyte characters in the application.  

The problem only occurs when I compile my application
in debug mode.  The release version runs without any


Attachments (0)

Change History (19)

comment:1 Changed 11 years ago by Vladimir Prus

Resolution: Nonewontfix
Severity: Showstopper
Status: assignedclosed

I don't have the slighest idea how char string can include multi-byte characters and how to handle that. Won't fix.

comment:2 Changed 9 years ago by anonymous

Component: Noneprogram_options
Resolution: wontfix
Severity: ShowstopperProblem
Status: closedreopened

comment:3 Changed 9 years ago by greg.ruthenbeck@…

This is still an issue and basically makes the component useless under Windows (since cannot run exe's compiled in Debug mode).

comment:4 Changed 9 years ago by Vladimir Prus

If you notice, the issue was originally closed with "Won't fix" comment. That still stands -- I have zero experience with multibyte strings, and no active windows experience, so there's no chance I'll fix it. Unless you plan on either providing a patch, or providing very detailed background and explanations for the necessary fix, I don't think keeping this issue open makes sense.

comment:5 Changed 9 years ago by greg.ruthenbeck@…

I've very little experience contributing to open-source projects the size of boost. By opening the bug I was hoping to flag the issue to other, more regular, contributors and/or a mailing list. Is this likely to happen? Since the bug is still present it would make sense to leave it open. At least that way, when next anyone contributes to the module they will have some documentation of the bug. I will continue to seek a solution but won't spend more than a few more hours on this over the next few days. If I don't resolve the issue in that time I won't use this module. In which case ideally the bug would remain open indefinitely pending a fix? Greg

comment:6 Changed 9 years ago by greg.ruthenbeck@…

This bug is only present when compiler option "Code Generation" is set to /MDd (Multi-threaded Debug DLL). If compiling as /MTd (using Linker option /Force:Multiple) the bug is not present.

The bug occurs on line 121, options_description.cpp, when string::npos is incorrect after string::find() call. Example: When string _name = "version,v", the following code has n = 11, and name.size() = 8.

std::string name(_name); string::size_type n = name.find(','); if (n != string::npos) {

assert(n == name.size()-2);

This suggests that the lib I am linking against "libboost_program_options-vc80-mt-gd-1_38.lib" has been built incorrectly? Since I don't have the source I cannot rebuild at this time to test this.

comment:7 Changed 8 years ago by Vladimir Prus

Is this issue still outstanding?

comment:8 Changed 8 years ago by Sascha Ochsenknecht

Would it help to replace:

assert(n == name.size()-2);

with: assert(n == (name.size() - 2*sizeof(std::string::char_type)));

Can somebody try that out?

Cheers, Sascha

comment:9 Changed 8 years ago by Sascha Ochsenknecht

better use:

 assert(n == (name.size() - 2*sizeof(std::string::value_type)));

comment:10 Changed 8 years ago by Sascha Ochsenknecht

Resolution: fixed
Status: reopenedclosed

(In [58232]) Modify assert, potentially Fixes #773

comment:11 Changed 8 years ago by Sascha Ochsenknecht

I checked in my proposal and set ticket to 'closed'.

If this issue still occurs, please feel free to re-open this ticket, but make sure that it is not a problem of your environment (wrong builds, compiler options etc.)

Thanks, Sascha

comment:12 Changed 8 years ago by Vladimir Prus

I am probably missing something here, but sizeof(std::string::value_type) is probably always 1. While multibyte strings are strings that consist of ordinary chars, but use more than one byte to represent a single 'logical character'.

comment:13 Changed 8 years ago by Sascha Ochsenknecht

I have no idea what is meant here with 'multibyte'. I assume if there is a multibyte string which uses e.g. 2 chars for a logical char, the library will fail at several other places.

I assume it's a strange platform specific behaviour with an old compiler version (opened 3 years ago). Nobody answered to this ticket anymore (you asked 3 months ago). So, I think its ok to close it.

We can revert my patch, I anyhow can not test or reproduce the bug ... I thought its maybe a potential solution ...

comment:14 Changed 8 years ago by Vladimir Prus

Hmm, it seems that your patch will only matter if sizeof(char) != 1, and in that case, it will probably do the wrong thing -- that is, 'n' will be in chars and you will decrement 2*number_of_bytes. So, I guess the patch better be reverted and this issue kept closed. Apparently, nobody cares.

comment:15 Changed 8 years ago by Sascha Ochsenknecht

uh, you're right ... it was wrong. However, I reverted it.

comment:16 Changed 6 years ago by anonymous

I had this problem for the past 24 hours and it has been driving me nuts. My problem was that I was building an application with

Runtime Library = Multi-threaded Debug DLL runtime library

But some of the static .lib libraries I was linking against were using

Runtime Library = Multi-threaded DLL runtime library

The boost libraries used the correct version of the runtime library, it was a different library that was wrong (opencv). boost::program_options saw the crash first when it tried to dtor vector<string> but any code or library that attempted to dtor a vector<string> would have crashed.

comment:17 Changed 20 months ago by anonymous

I ran into this assert error today. I'm using boost 1_59 with msvc12. My application crashed in debug mode when trying to 'add_options' to boost::options_description. I resolved my issue of ("version, v") by removing the space ("version,v").

comment:18 in reply to:  17 Changed 17 months ago by yuang86@…

Replying to anonymous:

I ran into this assert error today. I'm using boost 1_59 with msvc12. My application crashed in debug mode when trying to 'add_options' to boost::options_description. I resolved my issue of ("version, v") by removing the space ("version,v").

I have the same issue with boot 1_60 with msvc14. Taking the whitespace away also helped me.

comment:19 Changed 16 months ago by anonymous

Problem also occurs with VS 2015 and boost 1_61 in debug mode. That really is an annoyance, Whitespace removal did not help at all. Makes the library worthless imho.

Modify Ticket

Change Properties
Set your email in Preferences
as closed The owner will remain Vladimir Prus.
The resolution will be deleted.

Add Comment

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

Note: See TracTickets for help on using tickets.