Unverified Commit 76efbcdd by Dominic Hamon Committed by GitHub

Merge pull request #980 from brianwolfe/wolfe-fix-overflow-warning

timers: silence format overflow warning
parents 99c52f14 7cc06ef8
...@@ -189,8 +189,9 @@ std::string LocalDateTimeString() { ...@@ -189,8 +189,9 @@ std::string LocalDateTimeString() {
std::size_t timestamp_len; std::size_t timestamp_len;
long int offset_minutes; long int offset_minutes;
char tz_offset_sign = '+'; char tz_offset_sign = '+';
char tz_offset[kTzOffsetLen + 1]; // Long enough buffers to avoid format-overflow warnings
char storage[kTimestampLen + kTzOffsetLen + 1]; char tz_offset[128];
char storage[128];
#if defined(BENCHMARK_OS_WINDOWS) #if defined(BENCHMARK_OS_WINDOWS)
std::tm *timeinfo_p = ::localtime(&now); std::tm *timeinfo_p = ::localtime(&now);
...@@ -212,9 +213,10 @@ std::string LocalDateTimeString() { ...@@ -212,9 +213,10 @@ std::string LocalDateTimeString() {
offset_minutes *= -1; offset_minutes *= -1;
tz_offset_sign = '-'; tz_offset_sign = '-';
} }
tz_len = ::sprintf(tz_offset, "%c%02li:%02li", tz_offset_sign,
offset_minutes / 100, offset_minutes % 100); tz_len = ::snprintf(tz_offset, sizeof(tz_offset), "%c%02li:%02li",
CHECK(tz_len == 6); tz_offset_sign, offset_minutes / 100, offset_minutes % 100);
CHECK(tz_len == kTzOffsetLen);
((void)tz_len); // Prevent unused variable warning in optimized build. ((void)tz_len); // Prevent unused variable warning in optimized build.
} else { } else {
// Unknown offset. RFC3339 specifies that unknown local offsets should be // Unknown offset. RFC3339 specifies that unknown local offsets should be
...@@ -232,7 +234,9 @@ std::string LocalDateTimeString() { ...@@ -232,7 +234,9 @@ std::string LocalDateTimeString() {
timestamp_len = std::strftime(storage, sizeof(storage), "%Y-%m-%dT%H:%M:%S", timestamp_len = std::strftime(storage, sizeof(storage), "%Y-%m-%dT%H:%M:%S",
timeinfo_p); timeinfo_p);
CHECK(timestamp_len == kTimestampLen); CHECK(timestamp_len == kTimestampLen);
((void)timestamp_len); // Prevent unused variable warning in optimized build. // Prevent unused variable warning in optimized build.
((void)timestamp_len);
((void)kTimestampLen);
std::strncat(storage, tz_offset, kTzOffsetLen + 1); std::strncat(storage, tz_offset, kTzOffsetLen + 1);
return std::string(storage); return std::string(storage);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment