Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(41)

Side by Side Diff: base/debug/stack_trace_posix.cc

Issue 1187063003: Fix -INT_MIN integer overflow in itoa_r(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | base/third_party/symbolize/symbolize.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
OLDNEW
« no previous file with comments | « no previous file | base/third_party/symbolize/symbolize.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698