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 766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
777 buf[0] = '\000'; | 777 buf[0] = '\000'; |
778 return NULL; | 778 return NULL; |
779 } | 779 } |
780 | 780 |
781 char *start = buf; | 781 char *start = buf; |
782 | 782 |
783 uintptr_t j = i; | 783 uintptr_t j = i; |
784 | 784 |
785 // Handle negative numbers (only for base 10). | 785 // Handle negative numbers (only for base 10). |
786 if (i < 0 && base == 10) { | 786 if (i < 0 && base == 10) { |
787 j = -i; | 787 // This does "j = -i" while avoiding integer overflow. |
| 788 j = static_cast<uintptr_t>(-(i + 1)) + 1; |
788 | 789 |
789 // Make sure we can write the '-' character. | 790 // Make sure we can write the '-' character. |
790 if (++n > sz) { | 791 if (++n > sz) { |
791 buf[0] = '\000'; | 792 buf[0] = '\000'; |
792 return NULL; | 793 return NULL; |
793 } | 794 } |
794 *start++ = '-'; | 795 *start++ = '-'; |
795 } | 796 } |
796 | 797 |
797 // Loop until we have converted the entire number. Output at least one | 798 // Loop until we have converted the entire number. Output at least one |
(...skipping 26 matching lines...) Expand all Loading... |
824 *ptr = *start; | 825 *ptr = *start; |
825 *start++ = ch; | 826 *start++ = ch; |
826 } | 827 } |
827 return buf; | 828 return buf; |
828 } | 829 } |
829 | 830 |
830 } // namespace internal | 831 } // namespace internal |
831 | 832 |
832 } // namespace debug | 833 } // namespace debug |
833 } // namespace base | 834 } // namespace base |
OLD | NEW |