зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1542736
- Part 5: Replace std::isdigit with mozilla::IsAsciiDigit. r=jwalden
mozilla::IsAsciiDigit is equivalent to std::isdigit, except it's not necessary to worry about UB when calling it with an input which can't be represented as `unsigned char`. Differential Revision: https://phabricator.services.mozilla.com/D26508 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
db7c7bb385
Коммит
e801ce18a3
|
@ -196,11 +196,11 @@
|
|||
#include "mozilla/Move.h"
|
||||
#include "mozilla/Range.h"
|
||||
#include "mozilla/ScopeExit.h"
|
||||
#include "mozilla/TextUtils.h"
|
||||
#include "mozilla/TimeStamp.h"
|
||||
#include "mozilla/TypeTraits.h"
|
||||
#include "mozilla/Unused.h"
|
||||
|
||||
#include <ctype.h>
|
||||
#include <initializer_list>
|
||||
#include <string.h>
|
||||
#ifndef XP_WIN
|
||||
|
@ -1158,7 +1158,7 @@ static bool ParseZealModeNumericParam(CharRange text, uint32_t* paramOut) {
|
|||
}
|
||||
|
||||
for (auto c : text) {
|
||||
if (!isdigit(c)) {
|
||||
if (!mozilla::IsAsciiDigit(c)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,6 +58,7 @@ using mozilla::ArrayLength;
|
|||
using mozilla::Atomic;
|
||||
using mozilla::BitwiseCast;
|
||||
using mozilla::IsAsciiAlpha;
|
||||
using mozilla::IsAsciiDigit;
|
||||
using mozilla::IsFinite;
|
||||
using mozilla::IsNaN;
|
||||
using mozilla::NumbersAreIdentical;
|
||||
|
@ -2891,11 +2892,12 @@ static bool ToLocaleFormatHelper(JSContext* cx, HandleObject obj,
|
|||
if (strcmp(format, "%x") == 0 && result_len >= 6 &&
|
||||
/* Format %x means use OS settings, which may have 2-digit yr, so
|
||||
hack end of 3/11/22 or 11.03.22 or 11Mar22 to use 4-digit yr...*/
|
||||
!isdigit(buf[result_len - 3]) && isdigit(buf[result_len - 2]) &&
|
||||
isdigit(buf[result_len - 1]) &&
|
||||
!IsAsciiDigit(buf[result_len - 3]) &&
|
||||
IsAsciiDigit(buf[result_len - 2]) &&
|
||||
IsAsciiDigit(buf[result_len - 1]) &&
|
||||
/* ...but not if starts with 4-digit year, like 2022/3/11. */
|
||||
!(isdigit(buf[0]) && isdigit(buf[1]) && isdigit(buf[2]) &&
|
||||
isdigit(buf[3]))) {
|
||||
!(IsAsciiDigit(buf[0]) && IsAsciiDigit(buf[1]) &&
|
||||
IsAsciiDigit(buf[2]) && IsAsciiDigit(buf[3]))) {
|
||||
int year = int(YearFromTime(localTime));
|
||||
snprintf(buf + (result_len - 2), (sizeof buf) - (result_len - 2), "%d",
|
||||
year);
|
||||
|
|
|
@ -9,8 +9,7 @@
|
|||
#include "js/Initialization.h"
|
||||
|
||||
#include "mozilla/Assertions.h"
|
||||
|
||||
#include <ctype.h>
|
||||
#include "mozilla/TextUtils.h"
|
||||
|
||||
#include "jstypes.h"
|
||||
|
||||
|
@ -46,7 +45,7 @@ InitState JS::detail::libraryInitState;
|
|||
static unsigned MessageParameterCount(const char* format) {
|
||||
unsigned numfmtspecs = 0;
|
||||
for (const char* fmt = format; *fmt != '\0'; fmt++) {
|
||||
if (*fmt == '{' && isdigit(fmt[1])) {
|
||||
if (*fmt == '{' && mozilla::IsAsciiDigit(fmt[1])) {
|
||||
++numfmtspecs;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
#include "mozilla/TextUtils.h"
|
||||
#include "mozilla/Unused.h"
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#ifdef ANDROID
|
||||
|
@ -738,7 +737,7 @@ bool ExpandErrorArgumentsHelper(JSContext* cx, JSErrorCallback callback,
|
|||
fmt = efs->format;
|
||||
while (*fmt) {
|
||||
if (*fmt == '{') {
|
||||
if (isdigit(fmt[1])) {
|
||||
if (mozilla::IsAsciiDigit(fmt[1])) {
|
||||
int d = AsciiDigitToNumber(fmt[1]);
|
||||
MOZ_RELEASE_ASSERT(d < args.count());
|
||||
strncpy(out, args.args(d), args.lengths(d));
|
||||
|
|
Загрузка…
Ссылка в новой задаче