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
62f2997b
Unverified
Commit
62f2997b
authored
Oct 07, 2021
by
Carl Smedstad
Committed by
GitHub
Oct 07, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix assertion failure for JSON_DIAGNOSTICS (#3037)
* Fix assertion failure #3032
parent
ea528bbf
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
8 deletions
+45
-8
include/nlohmann/json.hpp
include/nlohmann/json.hpp
+14
-4
single_include/nlohmann/json.hpp
single_include/nlohmann/json.hpp
+14
-4
test/src/unit-diagnostics.cpp
test/src/unit-diagnostics.cpp
+17
-0
No files found.
include/nlohmann/json.hpp
View file @
62f2997b
...
...
@@ -3695,15 +3695,25 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
if
(
idx
>=
m_value
.
array
->
size
())
{
#if JSON_DIAGNOSTICS
// remember array size before resizing
const
auto
previous_size
=
m_value
.
array
->
size
();
// remember array size & capacity before resizing
const
auto
old_size
=
m_value
.
array
->
size
();
const
auto
old_capacity
=
m_value
.
array
->
capacity
();
#endif
m_value
.
array
->
resize
(
idx
+
1
);
#if JSON_DIAGNOSTICS
// set parent for values added above
set_parents
(
begin
()
+
static_cast
<
typename
iterator
::
difference_type
>
(
previous_size
),
static_cast
<
typename
iterator
::
difference_type
>
(
idx
+
1
-
previous_size
));
if
(
JSON_HEDLEY_UNLIKELY
(
m_value
.
array
->
capacity
()
!=
old_capacity
))
{
// capacity has changed: update all parents
set_parents
();
}
else
{
// set parent for values added above
set_parents
(
begin
()
+
static_cast
<
typename
iterator
::
difference_type
>
(
old_size
),
static_cast
<
typename
iterator
::
difference_type
>
(
idx
+
1
-
old_size
));
}
#endif
assert_invariant
();
}
return
m_value
.
array
->
operator
[](
idx
);
...
...
single_include/nlohmann/json.hpp
View file @
62f2997b
...
...
@@ -21101,15 +21101,25 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
if
(
idx
>=
m_value
.
array
->
size
())
{
#if JSON_DIAGNOSTICS
// remember array size before resizing
const
auto
previous_size
=
m_value
.
array
->
size
();
// remember array size & capacity before resizing
const
auto
old_size
=
m_value
.
array
->
size
();
const
auto
old_capacity
=
m_value
.
array
->
capacity
();
#endif
m_value
.
array
->
resize
(
idx
+
1
);
#if JSON_DIAGNOSTICS
// set parent for values added above
set_parents
(
begin
()
+
static_cast
<
typename
iterator
::
difference_type
>
(
previous_size
),
static_cast
<
typename
iterator
::
difference_type
>
(
idx
+
1
-
previous_size
));
if
(
JSON_HEDLEY_UNLIKELY
(
m_value
.
array
->
capacity
()
!=
old_capacity
))
{
// capacity has changed: update all parents
set_parents
();
}
else
{
// set parent for values added above
set_parents
(
begin
()
+
static_cast
<
typename
iterator
::
difference_type
>
(
old_size
),
static_cast
<
typename
iterator
::
difference_type
>
(
idx
+
1
-
old_size
));
}
#endif
assert_invariant
();
}
return
m_value
.
array
->
operator
[](
idx
);
...
...
test/src/unit-diagnostics.cpp
View file @
62f2997b
...
...
@@ -234,4 +234,21 @@ TEST_CASE("Better diagnostics")
root
.
push_back
(
lower
);
}
}
SECTION
(
"Regression test for https://github.com/nlohmann/json/issues/3032"
)
{
// reference operator[](size_type idx)
{
json
j_arr
=
json
::
array
();
j_arr
[
0
]
=
0
;
j_arr
[
1
]
=
1
;
j_arr
[
2
]
=
2
;
j_arr
[
3
]
=
3
;
j_arr
[
4
]
=
4
;
j_arr
[
5
]
=
5
;
j_arr
[
6
]
=
6
;
j_arr
[
7
]
=
7
;
json
j_arr_copy
=
j_arr
;
}
}
}
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