Thanks to visit codestin.com
Credit goes to github.com

Skip to content

<chrono>: format("%c", time_point) can lead to crash #3764

@achabense

Description

@achabense

This is a follow-up of #924. The same crash can happen even with format, as it will result in a call to put_time(which will make call to functions like _Strftime):

#include<format>
#include<iostream>
#include<chrono>
int main() {
	using namespace std::chrono;
	try {
		sys_time<seconds> t{seconds(335303598060)};
		std::cout << std::format("{:%c}", t);
	}
	catch (std::exception& e) {
		std::cout << e.what();// unreacheable.
	}
	return 0;
}

_Stream << _STD put_time<_CharT>(&_Time, _Fmt_string(_Spec, _Fmt_str));

Instead of an exception, the program will give a crashing error:

Unhandled exception at 0x00007FF80ACA1208 (ucrtbase.dll) in test.exe:
An invalid parameter was passed to a function that considers invalid parameters fatal.

Please consider doing some investigations for strftime series. The crash-on-failed-check behavior interacts really poorly with C++.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingchronoC++20 chrono

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions