From cb4089e49c0cdf441c28804a003e54472e0b7222 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Sun, 29 Jul 2018 17:27:30 -0700 Subject: [PATCH] Stratosphere: use isxdigit to check if char is hex. --- stratosphere/fs_mitm/source/fsmitm_utils.cpp | 12 +++++------- stratosphere/loader/source/ldr_patcher.cpp | 7 +++---- stratosphere/pm/source/pm_boot2.cpp | 12 +++++------- 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/stratosphere/fs_mitm/source/fsmitm_utils.cpp b/stratosphere/fs_mitm/source/fsmitm_utils.cpp index e499a5bf9..3542b8af8 100644 --- a/stratosphere/fs_mitm/source/fsmitm_utils.cpp +++ b/stratosphere/fs_mitm/source/fsmitm_utils.cpp @@ -13,13 +13,11 @@ static std::atomic_bool g_has_initialized = false; static bool IsHexadecimal(const char *str) { while (*str) { - if (('0' <= *str && *str <= '9') || - ('a' <= *str && *str <= 'f') || - ('A' <= *str && *str <= 'F')) { - str++; - } else { - return false; - } + if (isxdigit(*str)) { + str++; + } else { + return false; + } } return true; } diff --git a/stratosphere/loader/source/ldr_patcher.cpp b/stratosphere/loader/source/ldr_patcher.cpp index 569e44fcd..a0a6bdc24 100644 --- a/stratosphere/loader/source/ldr_patcher.cpp +++ b/stratosphere/loader/source/ldr_patcher.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include "ldr_patcher.hpp" @@ -28,11 +29,9 @@ static inline u8 HexNybbleToU8(const char nybble) { static bool MatchesBuildId(const char *name, size_t name_len, const u8 *build_id) { /* Validate name is hex build id. */ for (unsigned int i = 0; i < name_len - 4; i++) { - if (!(('0' <= name[i] && name[i] <= '9') || - ('a' <= name[i] && name[i] <= 'f') || - ('A' <= name[i] && name[i] <= 'F'))) { + if (isxdigit(name[i]) == 0) { return false; - } + } } /* Read build id from name. */ diff --git a/stratosphere/pm/source/pm_boot2.cpp b/stratosphere/pm/source/pm_boot2.cpp index e1aee4c4b..27618124a 100644 --- a/stratosphere/pm/source/pm_boot2.cpp +++ b/stratosphere/pm/source/pm_boot2.cpp @@ -12,13 +12,11 @@ static bool IsHexadecimal(const char *str) { while (*str) { - if (('0' <= *str && *str <= '9') || - ('a' <= *str && *str <= 'f') || - ('A' <= *str && *str <= 'F')) { - str++; - } else { - return false; - } + if (isxdigit(*str)) { + str++; + } else { + return false; + } } return true; }