mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-10-27 00:28:14 +00:00
Merge pull request #10814 from MarcZX10/marc/fix-ctime-fallback-buffer-race
fix(libc): give ctime's unrepresentable-time text a buffer per thread
This commit is contained in:
2 files changed
+16
-1
No files matched your search
@@ -604,7 +604,7 @@ char* APS5_VABI asctime_nid_postfix(const GuestTm* timeptr) {
|
||||
|
||||
char* APS5_VABI ctime_nid_postfix(const int64_t* timer) {
|
||||
if (const GuestTm* local = localtime_nid_postfix(timer)) return asctime_nid_postfix(local);
|
||||
static char unknown[26];
|
||||
static thread_local char unknown[26];
|
||||
std::memcpy(unknown, "??? ??? ?? ??:??:?? ????\n", sizeof(unknown));
|
||||
errno = EINVAL;
|
||||
return unknown;
|
||||
|
||||
@@ -496,6 +496,21 @@ int main() {
|
||||
*__error_nid_postfix() = 0;
|
||||
Require(std::strcmp(ctime_nid_postfix(&underflow), "??? ??? ?? ??:??:?? ????\n") == 0 && *__error_nid_postfix() == 22,
|
||||
"ctime of an unrepresentable time did not report it");
|
||||
{
|
||||
std::barrier finish(3);
|
||||
std::array<const char*, 2> texts{};
|
||||
std::array<std::thread, 2> readers;
|
||||
for (std::size_t index = 0; index < readers.size(); ++index) {
|
||||
readers[index] = std::thread([&, index] {
|
||||
texts[index] = ctime_nid_postfix(&underflow);
|
||||
finish.arrive_and_wait();
|
||||
});
|
||||
}
|
||||
const char* own = ctime_nid_postfix(&underflow);
|
||||
finish.arrive_and_wait();
|
||||
Require(texts[0] != texts[1] && texts[0] != own && texts[1] != own, "ctime of an unrepresentable time shared one buffer between threads");
|
||||
for (auto& reader : readers) reader.join();
|
||||
}
|
||||
|
||||
constexpr std::int64_t latest = std::numeric_limits<std::int64_t>::max();
|
||||
constexpr std::int64_t earliest = std::numeric_limits<std::int64_t>::min();
|
||||
|
||||
Reference in new issue
Block a user