Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
json
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
json
Commits
4e2fb1a5
Commit
4e2fb1a5
authored
Dec 13, 2016
by
Niels Lohmann
Committed by
GitHub
Dec 13, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #390 from qwename/integer-overflow
🔀
fix issue #380: Signed integer overflow check
parents
dfafd2c2
703d4baf
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
12 deletions
+12
-12
src/json.hpp
src/json.hpp
+6
-6
src/json.hpp.re2c
src/json.hpp.re2c
+6
-6
No files found.
src/json.hpp
View file @
4e2fb1a5
...
...
@@ -10619,19 +10619,19 @@ basic_json_parser_66:
// skip if definitely not an integer
if
(
type
!=
value_t
::
number_float
)
{
// multiply last value by ten and add the new digit
auto
temp
=
value
*
10
+
*
curptr
-
'0'
;
auto
digit
=
static_cast
<
number_unsigned_t
>
(
*
curptr
-
'0'
);
// test for overflow
if
(
temp
<
value
||
temp
>
max
)
// overflow if value * 10 + digit > max, move terms around
// to avoid overflow in intermediate values
if
(
value
>
(
max
-
digit
)
/
10
)
{
// overflow
type
=
value_t
::
number_float
;
}
else
{
// no overflow
- save it
value
=
temp
;
// no overflow
value
=
value
*
10
+
digit
;
}
}
}
...
...
src/json.hpp.re2c
View file @
4e2fb1a5
...
...
@@ -9769,19 +9769,19 @@ class basic_json
// skip if definitely not an integer
if (type != value_t::number_float)
{
// multiply last value by ten and add the new digit
auto temp = value * 10 + *curptr - '0';
auto digit = static_cast<number_unsigned_t>(*curptr - '0');
// test for overflow
if (temp < value || temp > max)
// overflow if value * 10 + digit > max, move terms around
// to avoid overflow in intermediate values
if (value > (max - digit) / 10)
{
// overflow
type = value_t::number_float;
}
else
{
// no overflow
- save it
value =
temp
;
// no overflow
value =
value * 10 + digit
;
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment