Boost C++ Libraries: Ticket #5446: Exception thrown by tz_database::load_from_file() on linux 2.6.37, boost1.46.1,gcc4.5.2 https://svn.boost.org/trac10/ticket/5446 <p> Hi, I tried to run the Flight Time Example in boost_1_46_1/doc/html/date_time/examples.html#date_time.examples.simple_time_zone, and an exception was thrown with error message: terminate called after throwing an instance of 'boost::exception_detail::clone_impl&lt;boost::exception_detail::error_info_injector&lt;boost::bad_lexical_cast&gt; &gt;' </p> <blockquote> <p> what(): bad lexical cast: source type value could not be interpreted as target </p> </blockquote> <p> When I debug with step into, I found it happened on line "<a class="missing wiki">Africa/Cairo</a>" of the date_time_zonespec.csv, because this is the first timezone which needs to call dst_adjustment_offsets(), and there was a '\r' at the end of the line, then when str_from_delimited_time_duration() called boost::lexical_cast&lt;unsigned short&gt;(*beg) the '\r' made the exception being raised. On linux, std::getline(ifs, buff) in load_from_file() will leave the '\r' in buff, which caused the exception. On win32 this would not happen. So the line ends '\r' needs to be removed in load_from_file() or at the beginning of parse_string(). </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/5446 Trac 1.4.3 anonymous Sun, 19 Jun 2011 22:09:22 GMT <link>https://svn.boost.org/trac10/ticket/5446#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5446#comment:1</guid> <description> <p> Please raise the severity of this bug, I have encountered it as well. </p> <p> The fallout from this is that tz_database is completely broken on linux, causing your application to crash, this is a very serious bug. </p> <p> The explanation above is 100% accurate, boost::lexical_cast is being called with an extra '\r' on lines which need DST adjustments. </p> <p> Here is a GDB snapshot from my application: </p> <hr /> <pre class="wiki">#6 0x000000000041a14f in boost::throw_exception&lt;boost::bad_lexical_cast&gt; (e=...) at /usr/include/boost/throw_exception.hpp:61 #7 0x0000000000417dd1 in boost::detail::lexical_cast&lt;unsigned short, std::basic_string&lt;char&gt;, false, char&gt; (arg=..., buf=0x7fffffffda20 "P\337\377\377\377\177", src_len=1) at /usr/include/boost/lexical_cast.hpp:1152 #8 0x0000000000415889 in boost::lexical_cast&lt;unsigned short, std::basic_string&lt;char&gt; &gt; (arg=...) at /usr/include/boost/lexical_cast.hpp:1174 #9 0x0000000000415a9f in boost::date_time::str_from_delimited_time_duration&lt;boost::posix_time::time_duration, char&gt; (s=...) at /usr/include/boost/date_time/time_parsing.hpp:79 #10 0x0000000000416606 in boost::date_time::tz_db_base&lt;boost::local_time::custom_time_zone_base&lt;char&gt;, boost::date_time::day_calc_dst_rule&lt;boost::local_time::nth_kday_rule_spec&gt; &gt;::parse_string (this=0x6d76e0, s=...) at /usr/include/boost/date_time/tz_db_base.hpp:358 #11 0x0000000000414426 in boost::date_time::tz_db_base&lt;boost::local_time::custom_time_zone_base&lt;char&gt;, boost::date_time::day_calc_dst_rule&lt;boost::local_time::nth_kday_rule_spec&gt; &gt;::load_from_file (this=0x6d76e0, pathspec=...) at /usr/include/boost/date_time/tz_db_base.hpp:183 ------------ </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Sun, 19 Jun 2011 22:35:16 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5446#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5446#comment:2</guid> <description> <p> Digging further, the cause of this problem is that the date_time_zonespec.csv file is shipped with DOS newlines. </p> <p> If you run: dos2unix date_time_zonespec.csv </p> <p> The file works properly. </p> <p> I have attached a diff vs. trunk which allows DOS newlines. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Sun, 19 Jun 2011 22:35:55 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/5446 https://svn.boost.org/trac10/ticket/5446 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">date_time.diff</span> </li> </ul> <p> timezone_db DOS newline support </p> Ticket Marshall Clow Wed, 13 Jul 2011 14:28:25 GMT <link>https://svn.boost.org/trac10/ticket/5446#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5446#comment:3</guid> <description> <p> I've checked the 1.47.0 release, and the svn repo. The svn:eol-style is 'native' (in both trunk and release), and the file in the release tarball has unix line endings. The same is true in the 1.46.1 .tar.bz2 file - so I'm not sure how you got DOS line endings. </p> </description> <category>Ticket</category> </item> <item> <author>nil@…</author> <pubDate>Fri, 20 Nov 2015 15:13:57 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5446#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5446#comment:4</guid> <description> <p> For the Internet searchers. The <code>load_from_file</code> method differs from <code>load_from_stream</code>, as the former ignores one line from the input and the latter does not. I've learnt it the hard way. </p> </description> <category>Ticket</category> </item> </channel> </rss>