Boost C++ Libraries: Ticket #7435: Crash with format using UTF16 strings on MacOS X https://svn.boost.org/trac10/ticket/7435 <p> Due to cross-platform issues with Microsoft Windows, we are using std::strings with unsigned shorts as UTF16 strings. </p> <p> We experience crashes when using boost::format in combination with these strings. </p> <p> Please find attach a simple fix which solves this issue for us. We are using this code since some years on Windows and Unix, too, without any negative side-effects. </p> <p> It would be great if you could double-check this change and commit it to future boost versions. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/7435 Trac 1.4.3 Franz Detro <franz.detro@…> Thu, 27 Sep 2012 08:38:27 GMT attachment set https://svn.boost.org/trac10/ticket/7435 https://svn.boost.org/trac10/ticket/7435 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">format-imbue.diff</span> </li> </ul> Ticket Steven Watanabe Thu, 14 Feb 2013 01:56:40 GMT <link>https://svn.boost.org/trac10/ticket/7435#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7435#comment:1</guid> <description> <p> Looking around in the code it appears that stream_format_state::apply_on itself calls oss.imbue. It isn't clear to me why this is crashing, but it seems to me that if apply_on fails if the locale isn't set, the simplest solution is to set the locale first rather than setting it in put only for to overwrite it immediately. </p> </description> <category>Ticket</category> </item> <item> <author>Franz Detro <franz.detro@…></author> <pubDate>Thu, 14 Feb 2013 11:30:36 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7435#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7435#comment:2</guid> <description> <p> The fix wasn't done by me, but I know that the crash happens when boost::format is used during app startup (e.g. during the initialization of static members). This may be related to the usage of unsigned short as character type or due to initialization order problems. </p> <p> If you have a better way to fix the issue, we're fine with this. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Joachim Faulhaber</dc:creator> <pubDate>Fri, 22 Feb 2013 15:51:44 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7435#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7435#comment:3</guid> <description> <p> At the tagged code line, the program crashes. I does not crash, if <code>os.imbue(*loc_default);</code> is called before. </p> <div class="wiki-code"><div class="code"><pre><span class="n">boost</span><span class="o">/</span><span class="n">format</span><span class="o">/</span><span class="n">internals</span><span class="p">.</span><span class="n">hpp</span><span class="p">(</span><span class="mi">104</span><span class="p">)</span><span class="o">:</span> <span class="k">template</span><span class="o">&lt;</span><span class="k">class</span> <span class="nc">Ch</span><span class="p">,</span> <span class="k">class</span> <span class="nc">Tr</span><span class="o">&gt;</span> <span class="kt">void</span> <span class="n">stream_format_state</span><span class="o">&lt;</span><span class="n">Ch</span><span class="p">,</span><span class="n">Tr</span><span class="o">&gt;::</span> <span class="n">apply_on</span> <span class="p">(</span><span class="n">basic_ios</span> <span class="o">&amp;</span> <span class="n">os</span><span class="p">,</span> <span class="n">boost</span><span class="o">::</span><span class="n">io</span><span class="o">::</span><span class="n">detail</span><span class="o">::</span><span class="n">locale_t</span> <span class="o">*</span> <span class="n">loc_default</span><span class="p">)</span> <span class="k">const</span> <span class="p">{</span> <span class="c1">// set the state of this stream according to our params</span> <span class="k">if</span><span class="p">(</span><span class="n">width_</span> <span class="o">!=</span> <span class="o">-</span><span class="mi">1</span><span class="p">)</span> <span class="n">os</span><span class="p">.</span><span class="n">width</span><span class="p">(</span><span class="n">width_</span><span class="p">);</span> <span class="k">if</span><span class="p">(</span><span class="n">precision_</span> <span class="o">!=</span> <span class="o">-</span><span class="mi">1</span><span class="p">)</span> <span class="n">os</span><span class="p">.</span><span class="n">precision</span><span class="p">(</span><span class="n">precision_</span><span class="p">);</span> <span class="k">if</span><span class="p">(</span><span class="n">fill_</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">)</span> <span class="n">os</span><span class="p">.</span><span class="n">fill</span><span class="p">(</span><span class="n">fill_</span><span class="p">);</span> <span class="c1">//&lt;== crashes here</span> <span class="n">os</span><span class="p">.</span><span class="n">flags</span><span class="p">(</span><span class="n">flags_</span><span class="p">);</span> <span class="n">os</span><span class="p">.</span><span class="n">clear</span><span class="p">(</span><span class="n">rdstate_</span><span class="p">);</span> <span class="n">os</span><span class="p">.</span><span class="n">exceptions</span><span class="p">(</span><span class="n">exceptions_</span><span class="p">);</span> <span class="cp">#if !defined(BOOST_NO_STD_LOCALE)</span> <span class="k">if</span><span class="p">(</span><span class="n">loc_</span><span class="p">)</span> <span class="n">os</span><span class="p">.</span><span class="n">imbue</span><span class="p">(</span><span class="n">loc_</span><span class="p">.</span><span class="n">get</span><span class="p">());</span> <span class="k">else</span> <span class="nf">if</span><span class="p">(</span><span class="n">loc_default</span><span class="p">)</span> <span class="n">os</span><span class="p">.</span><span class="n">imbue</span><span class="p">(</span><span class="o">*</span><span class="n">loc_default</span><span class="p">);</span> <span class="cp">#else</span> <span class="p">(</span><span class="kt">void</span><span class="p">)</span> <span class="n">loc_default</span><span class="p">;</span> <span class="c1">// keep compiler quiet if we don&#39;t support locales</span> <span class="cp">#endif </span> <span class="p">}</span> </pre></div></div><p> So we only need to move the bottom code (between <code>#if and #end</code>) to the beginning of the function. This change is done in the attached patch-file <code>internals.hpp.patch</code>. If there are no objections against this patch, I will apply it. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Joachim Faulhaber</dc:creator> <pubDate>Fri, 22 Feb 2013 17:43:58 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/7435 https://svn.boost.org/trac10/ticket/7435 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">internals.hpp.patch</span> </li> </ul> Ticket James E. King, III Sat, 14 Oct 2017 12:13:37 GMT owner, status changed https://svn.boost.org/trac10/ticket/7435#comment:4 https://svn.boost.org/trac10/ticket/7435#comment:4 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Samuel Krempp</span> to <span class="trac-author">James E. King, III</span> </li> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> <p> This was fixed in the 1.60.0 release: <a class="ext-link" href="https://github.com/boostorg/format/commit/6fd5847729f07d6f31d37ac3b2d37e78b6689997"><span class="icon">​</span>https://github.com/boostorg/format/commit/6fd5847729f07d6f31d37ac3b2d37e78b6689997</a> </p> <p> Once I have maintainer access I will uupdate the milestone accordingly. </p> Ticket James E. King, III Wed, 18 Oct 2017 19:18:10 GMT milestone changed https://svn.boost.org/trac10/ticket/7435#comment:5 https://svn.boost.org/trac10/ticket/7435#comment:5 <ul> <li><strong>milestone</strong> <span class="trac-field-old">To Be Determined</span> → <span class="trac-field-new">Boost 1.61.0</span> </li> </ul> Ticket James E. King, III Tue, 24 Oct 2017 18:34:57 GMT status changed; resolution set; milestone deleted https://svn.boost.org/trac10/ticket/7435#comment:6 https://svn.boost.org/trac10/ticket/7435#comment:6 <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-new">fixed</span> </li> <li><strong>milestone</strong> <span class="trac-field-deleted">Boost 1.61.0</span> </li> </ul> <p> I can't set the milestone appropriately, but it was fixed some time ago, so I am marking it fixed. </p> Ticket