diff options
author | Max Wipfli <mail@maxwipfli.ch> | 2021-06-01 21:18:08 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-06-03 13:31:46 +0200 |
commit | bc8d16ad28afb7436bfde1fd0a21faf73d652230 (patch) | |
tree | 7209f27957cc40f9cc1ce27a54f4a670a69a4683 /Userland/Libraries/LibJS/Runtime/GlobalObject.cpp | |
parent | 1c9d87c4558304cf2e955df7e4c49f9f60cd55f2 (diff) | |
download | serenity-bc8d16ad28afb7436bfde1fd0a21faf73d652230.zip |
Everywhere: Replace ctype.h to avoid narrowing conversions
This replaces ctype.h with CharacterType.h everywhere I could find
issues with narrowing conversions. While using it will probably make
sense almost everywhere in the future, the most critical places should
have been addressed.
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime/GlobalObject.cpp')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/GlobalObject.cpp | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp b/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp index 7d9d92b498..a38489aae5 100644 --- a/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp @@ -5,6 +5,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include <AK/CharacterTypes.h> #include <AK/Hex.h> #include <AK/Platform.h> #include <AK/TemporaryChange.h> @@ -56,7 +57,6 @@ #include <LibJS/Runtime/TypedArrayConstructor.h> #include <LibJS/Runtime/TypedArrayPrototype.h> #include <LibJS/Runtime/Value.h> -#include <ctype.h> namespace JS { @@ -249,16 +249,10 @@ JS_DEFINE_NATIVE_FUNCTION(GlobalObject::parse_int) } auto parse_digit = [&](u32 code_point, i32 radix) -> Optional<i32> { - i32 digit = -1; - - if (isdigit(code_point)) - digit = code_point - '0'; - else if (islower(code_point)) - digit = 10 + (code_point - 'a'); - else if (isupper(code_point)) - digit = 10 + (code_point - 'A'); - - if (digit == -1 || digit >= radix) + if (!is_ascii_hex_digit(code_point) || radix <= 0) + return {}; + auto digit = parse_ascii_hex_digit(code_point); + if (digit >= (u32)radix) return {}; return digit; }; |