Skip to content

<xloctime>: time_get::get can still assert 'istreambuf_iterator is not dereferenceable' when the format is longer than the stream #2848

Description

Issue #1071 was thought to be resolved by #1168 in VS 2019 16.8 with tests added by #1326, but this wasn't completely fixed. With today's main:

D:\GitHub\STL\out\build\x64>type meow.cpp
#include <ctime>
#include <iostream>
#include <iterator>
#include <locale>
#include <sstream>
#include <string>
using namespace std;

int main() {
    const locale loc{locale::classic()};
    const auto& tmget{use_facet<time_get<char>>(loc)};
    ios_base::iostate err{ios_base::goodbit};
    tm when{};
    const string fmt{"%X"};
    istringstream iss{"3:04"}; // "3:04:05" would succeed
    istreambuf_iterator<char> first{iss};
    const istreambuf_iterator<char> last{};

    tmget.get(first, last, iss, err, &when, fmt.data(), fmt.data() + fmt.size());

    if (err == ios_base::goodbit) {
        cout << "when.tm_hour: " << when.tm_hour << "\n";
        cout << "when.tm_min:  " << when.tm_min << "\n";
        cout << "when.tm_sec:  " << when.tm_sec << "\n";
    } else {
        cout << "time_get::get() failed.\n";
    }
}
D:\GitHub\STL\out\build\x64>cl /EHsc /nologo /W4 /MTd meow.cpp
meow.cpp

D:\GitHub\STL\out\build\x64>meow
---------------------------
Microsoft Visual C++ Runtime Library
---------------------------
Debug Assertion Failed!

Program: D:\GitHub\STL\out\build\x64\meow.exe
File: D:\GitHub\STL\out\build\x64\out\inc\iterator
Line: 399

Expression: istreambuf_iterator is not dereferenceable

For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.

(Press Retry to debug the application)

---------------------------
Abort   Retry   Ignore   
---------------------------

"%X" "parses the locale's standard time representation" (cppreference), which is why "3:04" is insufficient but "3:04:05" would succeed.

Compiler Explorer shows that Clang/libc++ and GCC/libstdc++ behave correctly here, printing "time_get::get() failed.": https://godbolt.org/z/anv7TTz4G

Originally reported as DevCom-362423 and Microsoft-internal VSO-713785 / AB#713785 .

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