-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Labels
bugSomething isn't workingSomething isn't workingfixedSomething works now, yay!Something works now, yay!
Description
Describe the bug
If an invalid or out-of-range tm struct is passed to std::put_time() it will lead to crash.
Command-line test case
C:\Temp>type repro.cpp
#include <iostream>
#include <iomanip>
#include <sstream>
#include <ctime>
int main() {
using namespace std;
time_t t = time(nullptr);
tm currentTime;
localtime_s(¤tTime, &t);
currentTime.tm_hour = 25; // set invalid hour
stringstream ss;
ss << put_time(¤tTime, "%Y-%m-%d-%H-%M");
}
C:\Temp>cl /EHsc /W4 /WX /std:c++20 .\repro.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.36.32546 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
repro.cpp
Microsoft (R) Incremental Linker Version 19.36.32546.0
Copyright (C) Microsoft Corporation. All rights reserved.
/out:repro.exe
repro.obj
C:\Temp>.\repro.exe
!!!App Crashed!!!
Expected behavior
The program should NOT crash.
Additional context
The crash is happening because of strftime which validates the data and if something is wrong it leads to crash if no handler is set.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingfixedSomething works now, yay!Something works now, yay!