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
efe41402
Commit
efe41402
authored
Feb 02, 2016
by
Milo Yip
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #399 MemoryPoolAllocator::Realloc expands fail
parent
d43f001a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
1 deletion
+22
-1
allocators.h
include/rapidjson/allocators.h
+3
-1
allocatorstest.cpp
test/unittest/allocatorstest.cpp
+19
-0
No files found.
include/rapidjson/allocators.h
View file @
efe41402
...
...
@@ -194,6 +194,9 @@ public:
if
(
newSize
==
0
)
return
NULL
;
originalSize
=
RAPIDJSON_ALIGN
(
originalSize
);
newSize
=
RAPIDJSON_ALIGN
(
newSize
);
// Do not shrink if new size is smaller than original
if
(
originalSize
>=
newSize
)
return
originalPtr
;
...
...
@@ -201,7 +204,6 @@ public:
// Simply expand it if it is the last allocation and there is sufficient space
if
(
originalPtr
==
reinterpret_cast
<
char
*>
(
chunkHead_
)
+
RAPIDJSON_ALIGN
(
sizeof
(
ChunkHeader
))
+
chunkHead_
->
size
-
originalSize
)
{
size_t
increment
=
static_cast
<
size_t
>
(
newSize
-
originalSize
);
increment
=
RAPIDJSON_ALIGN
(
increment
);
if
(
chunkHead_
->
size
+
increment
<=
chunkHead_
->
capacity
)
{
chunkHead_
->
size
+=
increment
;
return
originalPtr
;
...
...
test/unittest/allocatorstest.cpp
View file @
efe41402
...
...
@@ -81,3 +81,22 @@ TEST(Allocator, Alignment) {
}
#endif
}
TEST
(
Allocator
,
Issue399
)
{
MemoryPoolAllocator
<>
a
;
void
*
p
=
a
.
Malloc
(
100
);
void
*
q
=
a
.
Realloc
(
p
,
100
,
200
);
EXPECT_EQ
(
p
,
q
);
// exhuasive testing
for
(
size_t
j
=
1
;
j
<
32
;
j
++
)
{
a
.
Clear
();
a
.
Malloc
(
j
);
// some unaligned size
p
=
a
.
Malloc
(
1
);
for
(
size_t
i
=
1
;
i
<
1024
;
i
++
)
{
q
=
a
.
Realloc
(
p
,
i
,
i
+
1
);
EXPECT_EQ
(
p
,
q
);
p
=
q
;
}
}
}
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