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

Side by Side Diff: third_party/WebKit/Source/wtf/StdLibExtras.h

Issue 1814563002: wtf/CheckedArithmetic.h delegates to base/numerics/safe_math.h. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 10 matching lines...) Expand all
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 #ifndef WTF_StdLibExtras_h 26 #ifndef WTF_StdLibExtras_h
27 #define WTF_StdLibExtras_h 27 #define WTF_StdLibExtras_h
28 28
29 #include "wtf/Assertions.h" 29 #include "wtf/Assertions.h"
30 #include "wtf/CPU.h" 30 #include "wtf/CPU.h"
31 #include "wtf/CheckedArithmetic.h" 31 #include "wtf/CheckedNumeric.h"
32 #include "wtf/LeakAnnotations.h" 32 #include "wtf/LeakAnnotations.h"
33 #include <cstddef> 33 #include <cstddef>
34 34
35 #if ENABLE(ASSERT) 35 #if ENABLE(ASSERT)
36 #include "wtf/Noncopyable.h" 36 #include "wtf/Noncopyable.h"
37 #include "wtf/Threading.h" 37 #include "wtf/Threading.h"
38 38
39 class WTF_EXPORT StaticLocalVerifier { 39 class WTF_EXPORT StaticLocalVerifier {
40 WTF_MAKE_NONCOPYABLE(StaticLocalVerifier); 40 WTF_MAKE_NONCOPYABLE(StaticLocalVerifier);
41 public: 41 public:
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 FROM from; 146 FROM from;
147 TO to; 147 TO to;
148 } u; 148 } u;
149 u.from = from; 149 u.from = from;
150 return u.to; 150 return u.to;
151 } 151 }
152 152
153 template<typename To, typename From> 153 template<typename To, typename From>
154 inline To safeCast(From value) 154 inline To safeCast(From value)
155 { 155 {
156 RELEASE_ASSERT(isInBounds<To>(value)); 156 CheckedNumeric<To> checked(value);
157 return static_cast<To>(value); 157 return checked.ValueOrDie();
dcheng 2016/03/17 08:25:14 checked_cast is the //base/numerics/safe_conversio
Bret 2016/03/18 20:48:51 Done.
158 } 158 }
159 159
160 // Use the following macros to prevent errors caused by accidental 160 // Use the following macros to prevent errors caused by accidental
161 // implicit casting of function arguments. For example, this can 161 // implicit casting of function arguments. For example, this can
162 // be used to prevent overflows from non-promoting conversions. 162 // be used to prevent overflows from non-promoting conversions.
163 // 163 //
164 // Example: 164 // Example:
165 // 165 //
166 // HAS_STRICTLY_TYPED_ARG 166 // HAS_STRICTLY_TYPED_ARG
167 // void sendData(void* data, STRICTLY_TYPED_ARG(size)) 167 // void sendData(void* data, STRICTLY_TYPED_ARG(size))
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 inline void* operator new(size_t, NotNullTag, void* location) 202 inline void* operator new(size_t, NotNullTag, void* location)
203 { 203 {
204 ASSERT(location); 204 ASSERT(location);
205 return location; 205 return location;
206 } 206 }
207 207
208 using WTF::bitwise_cast; 208 using WTF::bitwise_cast;
209 using WTF::safeCast; 209 using WTF::safeCast;
210 210
211 #endif // WTF_StdLibExtras_h 211 #endif // WTF_StdLibExtras_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698