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

Side by Side Diff: third_party/base/numerics/safe_math_impl.h

Issue 1126243007: Update copy of safe_math_impl.h to take a fix from upstream: (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 5 years, 7 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 | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #ifndef PDFIUM_THIRD_PARTY_SAFE_MATH_IMPL_H_ 5 #ifndef PDFIUM_THIRD_PARTY_SAFE_MATH_IMPL_H_
6 #define PDFIUM_THIRD_PARTY_SAFE_MATH_IMPL_H_ 6 #define PDFIUM_THIRD_PARTY_SAFE_MATH_IMPL_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <cmath> 10 #include <cmath>
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 static_cast<IntermediateType>(x) * static_cast<IntermediateType>(y); 171 static_cast<IntermediateType>(x) * static_cast<IntermediateType>(y);
172 *validity = DstRangeRelationToSrcRange<T>(tmp); 172 *validity = DstRangeRelationToSrcRange<T>(tmp);
173 return static_cast<T>(tmp); 173 return static_cast<T>(tmp);
174 } 174 }
175 175
176 template <typename T> 176 template <typename T>
177 typename enable_if<std::numeric_limits<T>::is_integer&& std::numeric_limits< 177 typename enable_if<std::numeric_limits<T>::is_integer&& std::numeric_limits<
178 T>::is_signed&&(sizeof(T) * 2 > sizeof(uintmax_t)), 178 T>::is_signed&&(sizeof(T) * 2 > sizeof(uintmax_t)),
179 T>::type 179 T>::type
180 CheckedMul(T x, T y, RangeConstraint* validity) { 180 CheckedMul(T x, T y, RangeConstraint* validity) {
181 // if either side is zero then the result will be zero. 181 // If either side is zero then the result will be zero.
182 if (!(x || y)) { 182 if (!x || !y) {
183 return RANGE_VALID; 183 return RANGE_VALID;
184 184
185 } else if (x > 0) { 185 } else if (x > 0) {
186 if (y > 0) 186 if (y > 0)
187 *validity = 187 *validity =
188 x <= std::numeric_limits<T>::max() / y ? RANGE_VALID : RANGE_OVERFLOW; 188 x <= std::numeric_limits<T>::max() / y ? RANGE_VALID : RANGE_OVERFLOW;
189 else 189 else
190 *validity = y >= std::numeric_limits<T>::min() / x ? RANGE_VALID 190 *validity = y >= std::numeric_limits<T>::min() / x ? RANGE_VALID
191 : RANGE_UNDERFLOW; 191 : RANGE_UNDERFLOW;
192 192
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 StaticDstRangeRelationToSrcRange<T, Rhs>::value != 495 StaticDstRangeRelationToSrcRange<T, Rhs>::value !=
496 NUMERIC_RANGE_CONTAINED && 496 NUMERIC_RANGE_CONTAINED &&
497 sizeof(T) >= (2 * sizeof(Rhs)); 497 sizeof(T) >= (2 * sizeof(Rhs));
498 }; 498 };
499 499
500 } // namespace internal 500 } // namespace internal
501 } // namespace base 501 } // namespace base
502 } // namespace pdfium 502 } // namespace pdfium
503 503
504 #endif // PDFIUM_THIRD_PARTY_SAFE_MATH_IMPL_H_ 504 #endif // PDFIUM_THIRD_PARTY_SAFE_MATH_IMPL_H_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698