[Bug libstdc++/13900] New: time_put chokes on a trailing %

sebor at roguewave dot com gcc-bugzilla@gcc.gnu.org
Wed Jan 28 17:55:00 GMT 2004


The expected output of the program below is "Sun Jan  0 00:00:00 1900 %".
Instead, when compiled with gcc 3.3.2, the program dumps core. When it
encounters the trailing '%' in the format string, the time_put::do_put() member
function fails to check to see if it happens to be the last character and ends
up incrementing right past it (line 1986 of locale_facets.tcc).

Regards
Martin

#include <ctime>
#include <iostream>
#include <locale>

int main ()
{
    const std::time_put<char> &tp =
        std::use_facet<std::time_put<char> >(std::locale::classic ());

    std::tm tmb = { };

    const char fmt[] = "%c %";

    tp.put (std::ostreambuf_iterator<char>(std::cout.rdbuf ()),
            std::cout, ' ', &tmb, fmt, fmt + sizeof fmt - 1);

    std::cout << '\n';
}

-- 
           Summary: time_put chokes on a trailing %
           Product: gcc
           Version: 3.3.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: libstdc++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: sebor at roguewave dot com
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: all
  GCC host triplet: all
GCC target triplet: all


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13900



More information about the Gcc-bugs mailing list