Subject: [Boost-bugs] [Boost C++ Libraries] #3486: local_time::posix_time_zone_base::calc_zone Misuses String Iterator
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2009-09-24 20:47:16
#3486: local_time::posix_time_zone_base::calc_zone Misuses String Iterator
--------------------------------------------------+-------------------------
Reporter: Rob Stewart <robert.stewart@â¦> | Owner: az_sw_dude
Type: Bugs | Status: new
Milestone: Boost 1.41.0 | Component: date_time
Version: Boost 1.34.0 | Severity: Showstopper
Keywords: calc_zone iterator |
--------------------------------------------------+-------------------------
calc_zone() starts like this:
void calc_zone(const string_type& obj){
const char_type empty_string[2] = {'\0'};
stringstream_type ss(empty_string);
typename string_type::const_iterator sit = obj.begin();
string_type l_std_zone_abbrev, l_dst_zone_abbrev;
// get 'std' name/abbrev
while(std::isalpha(*sit)){
ss << *sit++;
}
Notice that sit is never compared against obj.end(). This code apparently
assumes that some non-alpha character will appear, if only a null
terminator. However, a checked STL flags *sit, in the conditional, as an
error when trying to dereference the end iterator.
The particular example I encountered in which it failed was when obj was a
std::string, of length 9, containing "Australia". There is no non-alpha
character before advancing the iterator to the end, so operator *() fails
with: "string iterator not dereferencable" in MSVC 8 (DevStudio 2005).
I suggest changing the loop to the following:
typename string_type::const_iterator it(obj.begin());
typename string_type::const_iterator end(obj.end());
// get 'std' name/abbrev
while (it != send && std::isalpha(*it))
{
ss << *it++;
}
(You can reuse end in the rest of the function, while you're at it!)
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/3486> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:01 UTC