Boost C++ Libraries: Ticket #773: program_options find assert fails with multibyte characters https://svn.boost.org/trac10/ticket/773 <pre class="wiki">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! </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/773 Trac 1.4.3 Vladimir Prus Thu, 28 Jun 2007 06:59:40 GMT status, resolution changed; severity set https://svn.boost.org/trac10/ticket/773#comment:1 https://svn.boost.org/trac10/ticket/773#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">wontfix</span> </li> <li><strong>severity</strong> → <span class="trac-field-new">Showstopper</span> </li> </ul> <p> I don't have the slighest idea how char string can include multi-byte characters and how to handle that. Won't fix. </p> Ticket anonymous Tue, 26 May 2009 06:03:54 GMT status, component, severity changed; resolution deleted https://svn.boost.org/trac10/ticket/773#comment:2 https://svn.boost.org/trac10/ticket/773#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">wontfix</span> </li> <li><strong>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">program_options</span> </li> <li><strong>severity</strong> <span class="trac-field-old">Showstopper</span> → <span class="trac-field-new">Problem</span> </li> </ul> Ticket greg.ruthenbeck@… Tue, 26 May 2009 06:06:11 GMT <link>https://svn.boost.org/trac10/ticket/773#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/773#comment:3</guid> <description> <p> This is still an issue and basically makes the component useless under Windows (since cannot run exe's compiled in Debug mode). </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Vladimir Prus</dc:creator> <pubDate>Tue, 26 May 2009 06:40:36 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/773#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/773#comment:4</guid> <description> <p> 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. </p> </description> <category>Ticket</category> </item> <item> <author>greg.ruthenbeck@…</author> <pubDate>Tue, 26 May 2009 06:54:32 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/773#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/773#comment:5</guid> <description> <p> 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 </p> </description> <category>Ticket</category> </item> <item> <author>greg.ruthenbeck@…</author> <pubDate>Tue, 26 May 2009 07:14:10 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/773#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/773#comment:6</guid> <description> <p> 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. </p> <p> 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. </p> <blockquote> <p> std::string name(_name); string::size_type n = name.find(','); if (n != string::npos) { </p> <blockquote> <p> assert(n == name.size()-2); </p> </blockquote> </blockquote> <p> 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. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Vladimir Prus</dc:creator> <pubDate>Sat, 29 Aug 2009 07:50:49 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/773#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/773#comment:7</guid> <description> <p> Is this issue still outstanding? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Sascha Ochsenknecht</dc:creator> <pubDate>Sun, 06 Dec 2009 16:54:16 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/773#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/773#comment:8</guid> <description> <p> Would it help to replace: </p> <p> <code>assert(n == name.size()-2);</code> </p> <p> with: <code>assert(n == (name.size() - 2*sizeof(std::string::char_type)));</code> </p> <p> Can somebody try that out? </p> <p> Cheers, Sascha </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Sascha Ochsenknecht</dc:creator> <pubDate>Sun, 06 Dec 2009 16:56:44 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/773#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/773#comment:9</guid> <description> <p> better use: </p> <pre class="wiki"> assert(n == (name.size() - 2*sizeof(std::string::value_type))); </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>Sascha Ochsenknecht</dc:creator> <pubDate>Tue, 08 Dec 2009 06:02:26 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/773#comment:10 https://svn.boost.org/trac10/ticket/773#comment:10 <ul> <li><strong>status</strong> <span class="trac-field-old">reopened</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/58232" title="Modify assert, potentially Fixes #773">[58232]</a>) Modify assert, potentially Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/773" title="#773: Bugs: program_options find assert fails with multibyte characters (closed: fixed)">#773</a> </p> Ticket Sascha Ochsenknecht Tue, 08 Dec 2009 06:04:48 GMT <link>https://svn.boost.org/trac10/ticket/773#comment:11 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/773#comment:11</guid> <description> <p> I checked in my proposal and set ticket to 'closed'. </p> <p> 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.) </p> <p> Thanks, Sascha </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Vladimir Prus</dc:creator> <pubDate>Tue, 08 Dec 2009 13:20:57 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/773#comment:12 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/773#comment:12</guid> <description> <p> 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'. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Sascha Ochsenknecht</dc:creator> <pubDate>Tue, 08 Dec 2009 13:43:15 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/773#comment:13 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/773#comment:13</guid> <description> <p> 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. </p> <p> 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. </p> <p> We can revert my patch, I anyhow can not test or reproduce the bug ... I thought its maybe a potential solution ... </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Vladimir Prus</dc:creator> <pubDate>Tue, 08 Dec 2009 14:43:49 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/773#comment:14 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/773#comment:14</guid> <description> <p> 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. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Sascha Ochsenknecht</dc:creator> <pubDate>Tue, 08 Dec 2009 14:58:07 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/773#comment:15 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/773#comment:15</guid> <description> <p> uh, you're right ... it was wrong. However, I reverted it. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Tue, 06 Mar 2012 00:13:33 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/773#comment:16 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/773#comment:16</guid> <description> <p> 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 </p> <blockquote> <p> Runtime Library = Multi-threaded Debug DLL runtime library </p> </blockquote> <p> But some of the static .lib libraries I was linking against were using </p> <blockquote> <p> Runtime Library = Multi-threaded DLL runtime library </p> </blockquote> <p> 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&lt;string&gt; but any code or library that attempted to dtor a vector&lt;string&gt; would have crashed. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Mon, 27 Jun 2016 14:58:33 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/773#comment:17 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/773#comment:17</guid> <description> <p> 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"). </p> </description> <category>Ticket</category> </item> <item> <author>yuang86@…</author> <pubDate>Tue, 27 Sep 2016 05:31:18 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/773#comment:18 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/773#comment:18</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/773#comment:17" title="Comment 17">anonymous</a>: </p> <blockquote class="citation"> <p> 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"). </p> </blockquote> <p> I have the same issue with boot 1_60 with msvc14. Taking the whitespace away also helped me. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Mon, 17 Oct 2016 13:08:31 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/773#comment:19 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/773#comment:19</guid> <description> <p> 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. </p> </description> <category>Ticket</category> </item> </channel> </rss>