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
5402458f
Commit
5402458f
authored
Dec 12, 2016
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
🚑
fixed an AddressSanitizer warning
parent
a25d5700
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
22 deletions
+28
-22
src/json.hpp
src/json.hpp
+14
-11
src/json.hpp.re2c
src/json.hpp.re2c
+14
-11
No files found.
src/json.hpp
View file @
5402458f
...
...
@@ -6271,7 +6271,7 @@ class basic_json
types.
@param[in] vec byte vector to read from
@param[in] current_index the psition in the vector after which to read
@param[in] current_index the p
o
sition in the vector after which to read
@return the next sizeof(T) bytes from @a vec, in reverse order as T
...
...
@@ -6280,20 +6280,24 @@ class basic_json
@throw std::out_of_range if there are less than sizeof(T)+1 bytes in the
vector @a vec to read
In the for loop, the bytes from the vector are copied in reverse order into
the return value. In the figures below, let sizeof(T)=4 and `i` be the loop
variable.
Precondition:
vec: | | | a | b | c | d |
| |
T: | | | | |
^
^
^ ^
current_index
idx
ptr sizeof(T)
vec: | | | a | b | c | d | T: | | | | |
^
^
^ ^
current_index
i
ptr sizeof(T)
Postcondition:
vec: | | | a | b | c | d |
| |
T: | d | c | b | a |
^ ^
^
|
idx
ptr
vec: | | | a | b | c | d | T: | d | c | b | a |
^ ^ ^
|
i
ptr
current_index
@sa Code from <http://stackoverflow.com/a/41031865/266378>.
@sa Code
adapted
from <http://stackoverflow.com/a/41031865/266378>.
*/
template
<
typename
T
>
static
T
get_from_vector
(
const
std
::
vector
<
uint8_t
>&
vec
,
const
size_t
current_index
)
...
...
@@ -6305,10 +6309,9 @@ class basic_json
T
result
;
uint8_t
*
ptr
=
reinterpret_cast
<
uint8_t
*>
(
&
result
);
size_t
idx
=
current_index
+
1
+
sizeof
(
T
);
while
(
idx
>
current_index
)
for
(
size_t
i
=
0
;
i
<
sizeof
(
T
);
++
i
)
{
*
ptr
++
=
vec
[
--
idx
];
*
ptr
++
=
vec
[
current_index
+
sizeof
(
T
)
-
i
];
}
return
result
;
}
...
...
src/json.hpp.re2c
View file @
5402458f
...
...
@@ -6271,7 +6271,7 @@ class basic_json
types.
@param[in] vec byte vector to read from
@param[in] current_index the psition in the vector after which to read
@param[in] current_index the p
o
sition in the vector after which to read
@return the next sizeof(T) bytes from @a vec, in reverse order as T
...
...
@@ -6280,20 +6280,24 @@ class basic_json
@throw std::out_of_range if there are less than sizeof(T)+1 bytes in the
vector @a vec to read
In the for loop, the bytes from the vector are copied in reverse order into
the return value. In the figures below, let sizeof(T)=4 and `i` be the loop
variable.
Precondition:
vec: | | | a | b | c | d |
| |
T: | | | | |
^
^
^ ^
current_index
idx
ptr sizeof(T)
vec: | | | a | b | c | d | T: | | | | |
^
^
^ ^
current_index
i
ptr sizeof(T)
Postcondition:
vec: | | | a | b | c | d |
| |
T: | d | c | b | a |
^ ^
^
|
idx
ptr
vec: | | | a | b | c | d | T: | d | c | b | a |
^ ^ ^
|
i
ptr
current_index
@sa Code from <http://stackoverflow.com/a/41031865/266378>.
@sa Code
adapted
from <http://stackoverflow.com/a/41031865/266378>.
*/
template<typename T>
static T get_from_vector(const std::vector<uint8_t>& vec, const size_t current_index)
...
...
@@ -6305,10 +6309,9 @@ class basic_json
T result;
uint8_t* ptr = reinterpret_cast<uint8_t*>(&result);
size_t idx = current_index + 1 + sizeof(T);
while (idx > current_index)
for (size_t i = 0; i < sizeof(T); ++i)
{
*ptr++ = vec[
--idx
];
*ptr++ = vec[
current_index + sizeof(T) - i
];
}
return result;
}
...
...
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