OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/debug/stack_trace.h" | 5 #include "base/debug/stack_trace.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <signal.h> | 9 #include <signal.h> |
10 #include <stdio.h> | 10 #include <stdio.h> |
(...skipping 770 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
781 buf[0] = '\000'; | 781 buf[0] = '\000'; |
782 return NULL; | 782 return NULL; |
783 } | 783 } |
784 | 784 |
785 char *start = buf; | 785 char *start = buf; |
786 | 786 |
787 uintptr_t j = i; | 787 uintptr_t j = i; |
788 | 788 |
789 // Handle negative numbers (only for base 10). | 789 // Handle negative numbers (only for base 10). |
790 if (i < 0 && base == 10) { | 790 if (i < 0 && base == 10) { |
791 j = -i; | 791 // This does "j = -i" while avoiding integer overflow. |
| 792 j = static_cast<uintptr_t>(-(i + 1)) + 1; |
792 | 793 |
793 // Make sure we can write the '-' character. | 794 // Make sure we can write the '-' character. |
794 if (++n > sz) { | 795 if (++n > sz) { |
795 buf[0] = '\000'; | 796 buf[0] = '\000'; |
796 return NULL; | 797 return NULL; |
797 } | 798 } |
798 *start++ = '-'; | 799 *start++ = '-'; |
799 } | 800 } |
800 | 801 |
801 // Loop until we have converted the entire number. Output at least one | 802 // Loop until we have converted the entire number. Output at least one |
(...skipping 26 matching lines...) Expand all Loading... |
828 *ptr = *start; | 829 *ptr = *start; |
829 *start++ = ch; | 830 *start++ = ch; |
830 } | 831 } |
831 return buf; | 832 return buf; |
832 } | 833 } |
833 | 834 |
834 } // namespace internal | 835 } // namespace internal |
835 | 836 |
836 } // namespace debug | 837 } // namespace debug |
837 } // namespace base | 838 } // namespace base |
OLD | NEW |