[PATCH] D125322: [llvm][json] Fix UINT64 json parsing

walter erquinigo via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 10 08:58:32 PDT 2022


wallace created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
wallace requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

https://reviews.llvm.org/D109347 added support for UINT64 json numeric
types. However, it seems that it didn't properly test uint64_t numbers
larger than the int64_t because the number parsing logic doesn't
have any special handling for these large numbers.

This diffs adds a handler for large numbers, and besides that, fixes the
parsing of signed types by checking for errno ERANGE, which is the
recommended way to check if parsing fails because of out of bounds
errors. Before this diff, strtoll was always returning a number within
the bounds of an int64_t and the bounds check it was doing was completely
superfluous.

As an interesting fact about the old implementation, when calling strtoll
with "18446744073709551615", the largest uint64_t, End was S.end(), even
though it didn't use all digits. Which means that this check can only be
used to identify if the numeric string is malformed or not.

This patch also adds additional tests for extreme cases.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D125322

Files:
  llvm/lib/Support/JSON.cpp
  llvm/unittests/Support/JSONTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125322.428397.patch
Type: text/x-patch
Size: 4083 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220510/de8c0a15/attachment.bin>


More information about the llvm-commits mailing list