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
6a905f93
Unverified
Commit
6a905f93
authored
Aug 01, 2018
by
Milo Yip
Committed by
GitHub
Aug 01, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1331 from JPEWdev/mem-alignment-fix
Fix SIGBUS due to unaligned access
parents
91df5631
748a652f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
21 deletions
+14
-21
rapidjson.h
include/rapidjson/rapidjson.h
+2
-7
allocatorstest.cpp
test/unittest/allocatorstest.cpp
+12
-14
No files found.
include/rapidjson/rapidjson.h
View file @
6a905f93
...
...
@@ -269,16 +269,11 @@
/*! \ingroup RAPIDJSON_CONFIG
\param x pointer to align
Some machines require strict data alignment. Currently the default uses 4 bytes
alignment on 32-bit platforms and 8 bytes alignment for 64-bit platforms.
Some machines require strict data alignment. The default is 8 bytes.
User can customize by defining the RAPIDJSON_ALIGN function macro.
*/
#ifndef RAPIDJSON_ALIGN
#if RAPIDJSON_64BIT == 1
#define RAPIDJSON_ALIGN(x) (((x) + static_cast<uint64_t>(7u)) & ~static_cast<uint64_t>(7u))
#else
#define RAPIDJSON_ALIGN(x) (((x) + 3u) & ~3u)
#endif
#define RAPIDJSON_ALIGN(x) (((x) + static_cast<size_t>(7u)) & ~static_cast<size_t>(7u))
#endif
///////////////////////////////////////////////////////////////////////////////
...
...
test/unittest/allocatorstest.cpp
View file @
6a905f93
...
...
@@ -63,23 +63,21 @@ TEST(Allocator, MemoryPoolAllocator) {
}
TEST
(
Allocator
,
Alignment
)
{
#if RAPIDJSON_64BIT == 1
EXPECT_EQ
(
RAPIDJSON_UINT64_C2
(
0x00000000
,
0x00000000
),
RAPIDJSON_ALIGN
(
0
));
for
(
uint64_t
i
=
1
;
i
<
8
;
i
++
)
{
EXPECT_EQ
(
RAPIDJSON_UINT64_C2
(
0x00000000
,
0x00000008
),
RAPIDJSON_ALIGN
(
i
));
EXPECT_EQ
(
RAPIDJSON_UINT64_C2
(
0x00000000
,
0x00000010
),
RAPIDJSON_ALIGN
(
RAPIDJSON_UINT64_C2
(
0x00000000
,
0x00000008
)
+
i
));
EXPECT_EQ
(
RAPIDJSON_UINT64_C2
(
0x00000001
,
0x00000000
),
RAPIDJSON_ALIGN
(
RAPIDJSON_UINT64_C2
(
0x00000000
,
0xFFFFFFF8
)
+
i
));
EXPECT_EQ
(
RAPIDJSON_UINT64_C2
(
0xFFFFFFFF
,
0xFFFFFFF8
),
RAPIDJSON_ALIGN
(
RAPIDJSON_UINT64_C2
(
0xFFFFFFFF
,
0xFFFFFFF0
)
+
i
));
if
(
sizeof
(
size_t
)
>=
8
)
{
EXPECT_EQ
(
RAPIDJSON_UINT64_C2
(
0x00000000
,
0x00000000
),
RAPIDJSON_ALIGN
(
0
));
for
(
uint64_t
i
=
1
;
i
<
8
;
i
++
)
{
EXPECT_EQ
(
RAPIDJSON_UINT64_C2
(
0x00000000
,
0x00000008
),
RAPIDJSON_ALIGN
(
i
));
EXPECT_EQ
(
RAPIDJSON_UINT64_C2
(
0x00000000
,
0x00000010
),
RAPIDJSON_ALIGN
(
RAPIDJSON_UINT64_C2
(
0x00000000
,
0x00000008
)
+
i
));
EXPECT_EQ
(
RAPIDJSON_UINT64_C2
(
0x00000001
,
0x00000000
),
RAPIDJSON_ALIGN
(
RAPIDJSON_UINT64_C2
(
0x00000000
,
0xFFFFFFF8
)
+
i
));
EXPECT_EQ
(
RAPIDJSON_UINT64_C2
(
0xFFFFFFFF
,
0xFFFFFFF8
),
RAPIDJSON_ALIGN
(
RAPIDJSON_UINT64_C2
(
0xFFFFFFFF
,
0xFFFFFFF0
)
+
i
));
}
}
#else
EXPECT_EQ
(
0u
,
RAPIDJSON_ALIGN
(
0u
));
for
(
uint32_t
i
=
1
;
i
<
4
;
i
++
)
{
EXPECT_EQ
(
4u
,
RAPIDJSON_ALIGN
(
i
));
EXPECT_EQ
(
8u
,
RAPIDJSON_ALIGN
(
4u
+
i
));
EXPECT_EQ
(
0xFFFFFFF8u
,
RAPIDJSON_ALIGN
(
0xFFFFFFF4u
+
i
));
EXPECT_EQ
(
0xFFFFFFFCu
,
RAPIDJSON_ALIGN
(
0xFFFFFFF8u
+
i
));
for
(
uint32_t
i
=
1
;
i
<
8
;
i
++
)
{
EXPECT_EQ
(
8u
,
RAPIDJSON_ALIGN
(
i
));
EXPECT_EQ
(
0xFFFFFFF8u
,
RAPIDJSON_ALIGN
(
0xFFFFFFF0u
+
i
));
}
#endif
}
TEST
(
Allocator
,
Issue399
)
{
...
...
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