Skip to content

Commit 45b3832

Browse files
jasonmolendaMichael137
authored andcommitted
[lldb] Fix printf formatting of std::time_t seconds (llvm#81078)
This formatter llvm#78609 was originally passing the signed seconds (which can refer to times in the past) with an unsigned printf formatter, and had tests that expected to see negative values from the printf which always failed on macOS. I'm not clear how they ever passed on any platform. Fix the printf to print seconds as a signed value, and re-enable the tests. (cherry picked from commit f219cda)
1 parent 826a40d commit 45b3832

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,15 +1108,16 @@ bool lldb_private::formatters::LibcxxChronoSysSecondsSummaryProvider(
11081108

11091109
const std::time_t seconds = ptr_sp->GetValueAsSigned(0);
11101110
if (seconds < chrono_timestamp_min || seconds > chrono_timestamp_max)
1111-
stream.Printf("timestamp=%ld s", seconds);
1111+
stream.Printf("timestamp=%" PRId64 " s", static_cast<int64_t>(seconds));
11121112
else {
11131113
std::array<char, 128> str;
11141114
std::size_t size =
11151115
std::strftime(str.data(), str.size(), "%FT%H:%M:%SZ", gmtime(&seconds));
11161116
if (size == 0)
11171117
return false;
11181118

1119-
stream.Printf("date/time=%s timestamp=%ld s", str.data(), seconds);
1119+
stream.Printf("date/time=%s timestamp=%" PRId64 " s", str.data(),
1120+
static_cast<int64_t>(seconds));
11201121
}
11211122

11221123
return true;

0 commit comments

Comments
 (0)