Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
R
rapidjson
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
rapidjson
Commits
4cd14b7c
Commit
4cd14b7c
authored
Apr 17, 2015
by
Milo Yip
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #305 from pah/fix/strict-memcpy
Avoid calling memcpy with NULL pointers
parents
30ace6fa
0c5c1538
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
5 deletions
+18
-5
allocators.h
include/rapidjson/allocators.h
+6
-1
document.h
include/rapidjson/document.h
+12
-4
No files found.
include/rapidjson/allocators.h
View file @
4cd14b7c
...
...
@@ -160,6 +160,9 @@ public:
//! Allocates a memory block. (concept Allocator)
void
*
Malloc
(
size_t
size
)
{
if
(
!
size
)
return
NULL
;
size
=
RAPIDJSON_ALIGN
(
size
);
if
(
chunkHead_
==
0
||
chunkHead_
->
size
+
size
>
chunkHead_
->
capacity
)
AddChunk
(
chunk_capacity_
>
size
?
chunk_capacity_
:
size
);
...
...
@@ -191,7 +194,9 @@ public:
// Realloc process: allocate and copy memory, do not free original buffer.
void
*
newBuffer
=
Malloc
(
newSize
);
RAPIDJSON_ASSERT
(
newBuffer
!=
0
);
// Do not handle out-of-memory explicitly.
return
std
::
memcpy
(
newBuffer
,
originalPtr
,
originalSize
);
if
(
originalSize
)
std
::
memcpy
(
newBuffer
,
originalPtr
,
originalSize
);
return
newBuffer
;
}
//! Frees a memory block (concept Allocator)
...
...
include/rapidjson/document.h
View file @
4cd14b7c
...
...
@@ -1579,16 +1579,24 @@ private:
// Initialize this value as array with initial data, without calling destructor.
void
SetArrayRaw
(
GenericValue
*
values
,
SizeType
count
,
Allocator
&
allocator
)
{
flags_
=
kArrayFlag
;
data_
.
a
.
elements
=
(
GenericValue
*
)
allocator
.
Malloc
(
count
*
sizeof
(
GenericValue
));
std
::
memcpy
(
data_
.
a
.
elements
,
values
,
count
*
sizeof
(
GenericValue
));
if
(
count
)
{
data_
.
a
.
elements
=
(
GenericValue
*
)
allocator
.
Malloc
(
count
*
sizeof
(
GenericValue
));
std
::
memcpy
(
data_
.
a
.
elements
,
values
,
count
*
sizeof
(
GenericValue
));
}
else
data_
.
a
.
elements
=
NULL
;
data_
.
a
.
size
=
data_
.
a
.
capacity
=
count
;
}
//! Initialize this value as object with initial data, without calling destructor.
void
SetObjectRaw
(
Member
*
members
,
SizeType
count
,
Allocator
&
allocator
)
{
flags_
=
kObjectFlag
;
data_
.
o
.
members
=
(
Member
*
)
allocator
.
Malloc
(
count
*
sizeof
(
Member
));
std
::
memcpy
(
data_
.
o
.
members
,
members
,
count
*
sizeof
(
Member
));
if
(
count
)
{
data_
.
o
.
members
=
(
Member
*
)
allocator
.
Malloc
(
count
*
sizeof
(
Member
));
std
::
memcpy
(
data_
.
o
.
members
,
members
,
count
*
sizeof
(
Member
));
}
else
data_
.
o
.
members
=
NULL
;
data_
.
o
.
size
=
data_
.
o
.
capacity
=
count
;
}
...
...
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