summaryrefslogtreecommitdiff
path: root/absl/time
diff options
context:
space:
mode:
authorGravatar Abseil Team <absl-team@google.com>2022-09-08 12:21:40 -0700
committerGravatar Copybara-Service <copybara-worker@google.com>2022-09-08 12:22:28 -0700
commit69199fcebe806a49a21992575b5227ee432f6917 (patch)
tree9013b1e4fc06bd7fa9a7d69ecdb9739eb184cfb8 /absl/time
parent518984e432e0597fd4e66a9c52148e8dec2bb46a (diff)
Fix "unsafe narrowing" warnings in absl, 9/n.
Addresses failures with the following, in some files: -Wshorten-64-to-32 -Wimplicit-int-conversion -Wsign-compare -Wsign-conversion -Wtautological-unsigned-zero-compare (This specific CL focuses on miscellaneous non-test source files.) Bug: chromium:1292951 PiperOrigin-RevId: 473054605 Change-Id: Ifd7b24966613ca915511a3a607095508068200b8
Diffstat (limited to 'absl/time')
-rw-r--r--absl/time/duration.cc4
-rw-r--r--absl/time/time.cc2
2 files changed, 3 insertions, 3 deletions
diff --git a/absl/time/duration.cc b/absl/time/duration.cc
index 1f4cf382..911e80f8 100644
--- a/absl/time/duration.cc
+++ b/absl/time/duration.cc
@@ -617,7 +617,7 @@ timespec ToTimespec(Duration d) {
rep_lo -= kTicksPerSecond;
}
}
- ts.tv_sec = rep_hi;
+ ts.tv_sec = static_cast<decltype(ts.tv_sec)>(rep_hi);
if (ts.tv_sec == rep_hi) { // no time_t narrowing
ts.tv_nsec = rep_lo / kTicksPerNanosecond;
return ts;
@@ -691,7 +691,7 @@ namespace {
char* Format64(char* ep, int width, int64_t v) {
do {
--width;
- *--ep = '0' + (v % 10); // contiguous digits
+ *--ep = static_cast<char>('0' + (v % 10)); // contiguous digits
} while (v /= 10);
while (--width >= 0) *--ep = '0'; // zero pad
return ep;
diff --git a/absl/time/time.cc b/absl/time/time.cc
index 718b88c8..7256a699 100644
--- a/absl/time/time.cc
+++ b/absl/time/time.cc
@@ -297,7 +297,7 @@ timespec ToTimespec(Time t) {
timespec ts;
absl::Duration d = time_internal::ToUnixDuration(t);
if (!time_internal::IsInfiniteDuration(d)) {
- ts.tv_sec = time_internal::GetRepHi(d);
+ ts.tv_sec = static_cast<decltype(ts.tv_sec)>(time_internal::GetRepHi(d));
if (ts.tv_sec == time_internal::GetRepHi(d)) { // no time_t narrowing
ts.tv_nsec = time_internal::GetRepLo(d) / 4; // floor
return ts;