Skip to content

<iomanip>: std::get_time asserts with "istreambuf_iterator is not dereferenceable" when format is longer than the stream #1071

Description

@fsb4000

Describe the bug
std::get_time doesn't stop parsing the input stream as soon as a mismatch is found or stream is eof, but continues until the format string is exhausted instead. This provokes a dereference of the input stream iterator even when it is at the eof. In debug builds it raises an assert. In release builds it is silently ignored.

Command-line test case

#include <sstream>
#include <iomanip>
#include <string>
int main()
{
    std::string s("123");
    std::tm t = {};
    std::istringstream ss(s);
    ss >> std::get_time(&t, "%Y-%m-%d %H:%M:%S");
    if (ss.fail()) {
        return 1;
    }
}

Expected behavior
Should setstate failbit in the stream instead of the assertion.
test

STL version
Microsoft Visual Studio Community 2019
Version 16.6.4

Additional context
See also:

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixedSomething works now, yay!

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions