| OLD | NEW |
| 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 |
| 11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
| 12 * | 12 * |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
| 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 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 "base/numerics/safe_conversions.h" | |
| 30 #include "wtf/Assertions.h" | 29 #include "wtf/Assertions.h" |
| 31 #include "wtf/CPU.h" | 30 #include "wtf/CPU.h" |
| 31 #include "wtf/CheckedArithmetic.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 Loading... |
| 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 return base::checked_cast<To>(value); | 156 RELEASE_ASSERT(isInBounds<To>(value)); |
| 157 return static_cast<To>(value); |
| 157 } | 158 } |
| 158 | 159 |
| 159 // Use the following macros to prevent errors caused by accidental | 160 // Use the following macros to prevent errors caused by accidental |
| 160 // implicit casting of function arguments. For example, this can | 161 // implicit casting of function arguments. For example, this can |
| 161 // be used to prevent overflows from non-promoting conversions. | 162 // be used to prevent overflows from non-promoting conversions. |
| 162 // | 163 // |
| 163 // Example: | 164 // Example: |
| 164 // | 165 // |
| 165 // HAS_STRICTLY_TYPED_ARG | 166 // HAS_STRICTLY_TYPED_ARG |
| 166 // 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 Loading... |
| 201 inline void* operator new(size_t, NotNullTag, void* location) | 202 inline void* operator new(size_t, NotNullTag, void* location) |
| 202 { | 203 { |
| 203 ASSERT(location); | 204 ASSERT(location); |
| 204 return location; | 205 return location; |
| 205 } | 206 } |
| 206 | 207 |
| 207 using WTF::bitwise_cast; | 208 using WTF::bitwise_cast; |
| 208 using WTF::safeCast; | 209 using WTF::safeCast; |
| 209 | 210 |
| 210 #endif // WTF_StdLibExtras_h | 211 #endif // WTF_StdLibExtras_h |
| OLD | NEW |