Index: base/debug/stack_trace_posix.cc |
diff --git a/base/debug/stack_trace_posix.cc b/base/debug/stack_trace_posix.cc |
index 76cb5249854a335e0a727e3c47830d88102be541..8749bede89e2684f24504a8a6e9305592969b739 100644 |
--- a/base/debug/stack_trace_posix.cc |
+++ b/base/debug/stack_trace_posix.cc |
@@ -788,7 +788,8 @@ char *itoa_r(intptr_t i, char *buf, size_t sz, int base, size_t padding) { |
// Handle negative numbers (only for base 10). |
if (i < 0 && base == 10) { |
- j = -i; |
+ // This does "j = -i" while avoiding integer overflow. |
+ j = static_cast<uintptr_t>(-(i + 1)) + 1; |
// Make sure we can write the '-' character. |
if (++n > sz) { |