diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2022-07-04 19:20:19 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2023-02-08 19:02:26 +0000 |
commit | 81ad626541db97eb356e2c1d4a20eb2a26a766ab (patch) | |
tree | 311b6a8987c32b1e1dcbab65c54cfac3fdb56175 /contrib/llvm-project/llvm/lib/Support/JSON.cpp | |
parent | 5fff09660e06a66bed6482da9c70df328e16bbb6 (diff) | |
parent | 145449b1e420787bb99721a429341fa6be3adfb6 (diff) |
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Support/JSON.cpp')
-rw-r--r-- | contrib/llvm-project/llvm/lib/Support/JSON.cpp | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/contrib/llvm-project/llvm/lib/Support/JSON.cpp b/contrib/llvm-project/llvm/lib/Support/JSON.cpp index 20babbe56d86..b87e39f0a963 100644 --- a/contrib/llvm-project/llvm/lib/Support/JSON.cpp +++ b/contrib/llvm-project/llvm/lib/Support/JSON.cpp @@ -509,13 +509,25 @@ bool Parser::parseNumber(char First, Value &Out) { S.push_back(next()); char *End; // Try first to parse as integer, and if so preserve full 64 bits. - // strtoll returns long long >= 64 bits, so check it's in range too. - auto I = std::strtoll(S.c_str(), &End, 10); - if (End == S.end() && I >= std::numeric_limits<int64_t>::min() && - I <= std::numeric_limits<int64_t>::max()) { + // We check for errno for out of bounds errors and for End == S.end() + // to make sure that the numeric string is not malformed. + errno = 0; + int64_t I = std::strtoll(S.c_str(), &End, 10); + if (End == S.end() && errno != ERANGE) { Out = int64_t(I); return true; } + // strtroull has a special handling for negative numbers, but in this + // case we don't want to do that because negative numbers were already + // handled in the previous block. + if (First != '-') { + errno = 0; + uint64_t UI = std::strtoull(S.c_str(), &End, 10); + if (End == S.end() && errno != ERANGE) { + Out = UI; + return true; + } + } // If it's not an integer Out = std::strtod(S.c_str(), &End); return End == S.end() || parseError("Invalid JSON value (number?)"); |