-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
<chrono>
: format("%c", time_point)
can lead to crash
#3764
Comments
Here is a rough test for Code to testint test() {
} |
<chrono>
: format("%c", time_point)
can cause the program to crash<chrono>
: format("%c", time_point)
can lead to crash
Thanks for the test cases. The first thing we need to understand is whether this is a bug in the UCRT |
This is a time in the year 12595. The UCRT only considers the years [0, 9999] valid, see Windows Kits\10\Source\10.0.22000.0\ucrt\time\wcsftime.cpp, line 963. POSIX.1-2017 adds "The
|
The main problem is that in |
Below is a more exhaustive list that shows all specifiers that crash on #include<format>
#include<iostream>
#include<chrono>
#include<ranges>
//lists from https://en.cppreference.com/w/cpp/chrono/system_clock/formatter
// invalid by the standard
const auto specs_invalid = {
"Q","q"
};
const auto specs = {
"C","y","Y","b","h","B","m","d","e","a","A","u","w",
//"g", // crash due to put_time
//"G", // crash due to put_time
"V","j","U","W","D","F",
//"x", // crash due to put_time
"H","I","M","S","p","R","T","r","X","z","Z",
//"c", // crash due to put_time
};
// O
const auto specs_O = {
//"Oy", // crash due to put_time
"Om","Od","Oe","Oe","Ow","OV","OU","OW","OH","OI","OM","OS","Oz"
};
// E
const auto specs_E = {
//"EC", // crash due to put_time
//"Ey", // crash due to put_time
//"EY", // crash due to put_time
//"Ex", // crash due to put_time
"EX","Ez",
// "Ec", // crash due to put_time
};
int main() {
using namespace std::chrono;
try {
sys_time<seconds> t{ seconds(335303598060) };
auto fmt_arg = make_format_args(t);
auto all_specs = { specs,specs_O,specs_E };
for (auto str : std::views::join(all_specs)) {
char fmt[10];
sprintf_s(fmt, "{:%%%s}", str);
printf("trying %s", fmt);
auto str = std::vformat(fmt, fmt_arg);
puts(str.c_str());
}
}
catch (std::exception& e) {
std::cout << e.what();
}
} |
@achabense Although you've closed the issue it seems I've addressed it in #4840 and #4883 (the second PR is still in development). Tried the code from your last comment locally and it does not crash anymore. Update: Fixed! |
This is a follow-up of #924. The same crash can happen even with
format
, as it will result in a call toput_time
(which will make call to functions like_Strftime
):STL/stl/inc/chrono
Line 5470 in c8d1efb
Instead of an exception, the program will give a crashing error:
Please consider doing some investigations for
strftime
series. The crash-on-failed-check behavior interacts really poorly with C++.The text was updated successfully, but these errors were encountered: