diff options
author | Abseil Team <absl-team@google.com> | 2022-08-04 05:19:56 -0700 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2022-08-04 05:20:40 -0700 |
commit | 751ade00ee347abef5dac7248db851e3f2012e14 (patch) | |
tree | d5946590986f065406933c68bda8fd6af3013473 /absl/time/duration.cc | |
parent | 07360899e64ded32e9a5e304bd6a3b6a0ff266bc (diff) |
Fix "unsafe narrowing" warnings in absl, 3/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 .cc files in dirs n-t, except string.)
Bug: chromium:1292951
PiperOrigin-RevId: 465287204
Change-Id: I0fe98ff78bf3c08d86992019eb626755f8b6803e
Diffstat (limited to 'absl/time/duration.cc')
-rw-r--r-- | absl/time/duration.cc | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/absl/time/duration.cc b/absl/time/duration.cc index 2bba62da..1f4cf382 100644 --- a/absl/time/duration.cc +++ b/absl/time/duration.cc @@ -645,7 +645,7 @@ timeval ToTimeval(Duration d) { ts.tv_nsec -= 1000 * 1000 * 1000; } } - tv.tv_sec = ts.tv_sec; + tv.tv_sec = static_cast<decltype(tv.tv_sec)>(ts.tv_sec); if (tv.tv_sec != ts.tv_sec) { // narrowing if (ts.tv_sec < 0) { tv.tv_sec = std::numeric_limits<decltype(tv.tv_sec)>::min(); @@ -728,7 +728,7 @@ void AppendNumberUnit(std::string* out, int64_t n, DisplayUnit unit) { char* const ep = buf + sizeof(buf); char* bp = Format64(ep, 0, n); if (*bp != '0' || bp + 1 != ep) { - out->append(bp, ep - bp); + out->append(bp, static_cast<size_t>(ep - bp)); out->append(unit.abbr.data(), unit.abbr.size()); } } @@ -745,12 +745,12 @@ void AppendNumberUnit(std::string* out, double n, DisplayUnit unit) { int64_t int_part = d; if (int_part != 0 || frac_part != 0) { char* bp = Format64(ep, 0, int_part); // always < 1000 - out->append(bp, ep - bp); + out->append(bp, static_cast<size_t>(ep - bp)); if (frac_part != 0) { out->push_back('.'); bp = Format64(ep, prec, frac_part); while (ep[-1] == '0') --ep; - out->append(bp, ep - bp); + out->append(bp, static_cast<size_t>(ep - bp)); } out->append(unit.abbr.data(), unit.abbr.size()); } @@ -841,7 +841,7 @@ bool ConsumeDurationNumber(const char** dpp, const char* ep, int64_t* int_part, // in "*unit". The given string pointer is modified to point to the first // unconsumed char. bool ConsumeDurationUnit(const char** start, const char* end, Duration* unit) { - size_t size = end - *start; + size_t size = static_cast<size_t>(end - *start); switch (size) { case 0: return false; |