Opened 16 years ago

Closed 13 years ago

Last modified 6 years 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:

Description

I have experienced the following error when running my
application.

Assertion failed: n == name.size()-2, file
C:\....\Libraries\OpenSource\boost\libs\program_options\build\../src/options_description.cpp,
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:

"help,h"

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

Cheer,
Brian!

Change History (19)

comment:1 by Vladimir Prus, 15 years ago

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 by anonymous, 13 years ago

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

comment:3 by greg.ruthenbeck@…, 13 years ago

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

comment:4 by Vladimir Prus, 13 years ago

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 by greg.ruthenbeck@…, 13 years ago

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 by greg.ruthenbeck@…, 13 years ago

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 by Vladimir Prus, 13 years ago

Is this issue still outstanding?

comment:8 by Sascha Ochsenknecht, 13 years ago

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 by Sascha Ochsenknecht, 13 years ago

better use:

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

comment:10 by Sascha Ochsenknecht, 13 years ago

Resolution: fixed
Status: reopenedclosed

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

comment:11 by Sascha Ochsenknecht, 13 years ago

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 by Vladimir Prus, 13 years ago

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 by Sascha Ochsenknecht, 13 years ago

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 by Vladimir Prus, 13 years ago

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 by Sascha Ochsenknecht, 13 years ago

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

comment:16 by anonymous, 11 years ago

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 by anonymous, 6 years ago

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

in reply to:  17 comment:18 by yuang86@…, 6 years ago

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 by anonymous, 6 years ago

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.

Note: See TracTickets for help on using tickets.