Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
StephanTLavavej opened this issue Jul 7, 2022 · 0 comments · Fixed by #2851
Labels
bug Something isn't working fixed Something works now, yay!

Comments

@StephanTLavavej
Copy link
Member

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 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed Something works now, yay!
Projects
None yet
1 participant