Skip to content

Commit 2bbd33b

Browse files
authored
Merge pull request Tencent#1323 from pah/fix-memaccess
Fix warnings/errors on GCC 7/8 (-Wclass-memaccess, -Wsign-conversion, -Wformat-overflow)
2 parents 4b4583b + 1525116 commit 2bbd33b

File tree

5 files changed

+16
-19
lines changed

5 files changed

+16
-19
lines changed

include/rapidjson/document.h

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,7 +1513,7 @@ class GenericValue {
15131513
MemberIterator pos = MemberBegin() + (first - MemberBegin());
15141514
for (MemberIterator itr = pos; itr != last; ++itr)
15151515
itr->~Member();
1516-
std::memmove(&*pos, &*last, static_cast<size_t>(MemberEnd() - last) * sizeof(Member));
1516+
std::memmove(static_cast<void*>(&*pos), &*last, static_cast<size_t>(MemberEnd() - last) * sizeof(Member));
15171517
data_.o.size -= static_cast<SizeType>(last - first);
15181518
return pos;
15191519
}
@@ -1716,8 +1716,8 @@ class GenericValue {
17161716
RAPIDJSON_ASSERT(last <= End());
17171717
ValueIterator pos = Begin() + (first - Begin());
17181718
for (ValueIterator itr = pos; itr != last; ++itr)
1719-
itr->~GenericValue();
1720-
std::memmove(pos, last, static_cast<size_t>(End() - last) * sizeof(GenericValue));
1719+
itr->~GenericValue();
1720+
std::memmove(static_cast<void*>(pos), last, static_cast<size_t>(End() - last) * sizeof(GenericValue));
17211721
data_.a.size -= static_cast<SizeType>(last - first);
17221722
return pos;
17231723
}
@@ -2032,12 +2032,7 @@ class GenericValue {
20322032
if (count) {
20332033
GenericValue* e = static_cast<GenericValue*>(allocator.Malloc(count * sizeof(GenericValue)));
20342034
SetElementsPointer(e);
2035-
RAPIDJSON_DIAG_PUSH
2036-
#if defined(__GNUC__) && __GNUC__ >= 8
2037-
RAPIDJSON_DIAG_OFF(class-memaccess) // ignore complains from gcc that no trivial copy constructor exists.
2038-
#endif
2039-
std::memcpy(e, values, count * sizeof(GenericValue));
2040-
RAPIDJSON_DIAG_POP
2035+
std::memcpy(static_cast<void*>(e), values, count * sizeof(GenericValue));
20412036
}
20422037
else
20432038
SetElementsPointer(0);
@@ -2050,12 +2045,7 @@ RAPIDJSON_DIAG_POP
20502045
if (count) {
20512046
Member* m = static_cast<Member*>(allocator.Malloc(count * sizeof(Member)));
20522047
SetMembersPointer(m);
2053-
RAPIDJSON_DIAG_PUSH
2054-
#if defined(__GNUC__) && __GNUC__ >= 8
2055-
RAPIDJSON_DIAG_OFF(class-memaccess) // ignore complains from gcc that no trivial copy constructor exists.
2056-
#endif
2057-
std::memcpy(m, members, count * sizeof(Member));
2058-
RAPIDJSON_DIAG_POP
2048+
std::memcpy(static_cast<void*>(m), members, count * sizeof(Member));
20592049
}
20602050
else
20612051
SetMembersPointer(0);

include/rapidjson/schema.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ class Schema {
464464
enum_ = static_cast<uint64_t*>(allocator_->Malloc(sizeof(uint64_t) * v->Size()));
465465
for (ConstValueIterator itr = v->Begin(); itr != v->End(); ++itr) {
466466
typedef Hasher<EncodingType, MemoryPoolAllocator<> > EnumHasherType;
467-
char buffer[256 + 24];
467+
char buffer[256u + 24];
468468
MemoryPoolAllocator<> hasherAllocator(buffer, sizeof(buffer));
469469
EnumHasherType h(&hasherAllocator, 256);
470470
itr->Accept(h);

test/perftest/schematest.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111

1212
using namespace rapidjson;
1313

14+
RAPIDJSON_DIAG_PUSH
15+
#if defined(__GNUC__) && __GNUC__ >= 7
16+
RAPIDJSON_DIAG_OFF(format-overflow)
17+
#endif
18+
1419
template <typename Allocator>
1520
static char* ReadFile(const char* filename, Allocator& allocator) {
1621
const char *paths[] = {
@@ -42,6 +47,8 @@ static char* ReadFile(const char* filename, Allocator& allocator) {
4247
return json;
4348
}
4449

50+
RAPIDJSON_DIAG_POP
51+
4552
class Schema : public PerfTest {
4653
public:
4754
Schema() {}

test/unittest/schematest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1762,7 +1762,7 @@ class RemoteSchemaDocumentProvider : public IGenericRemoteSchemaDocumentProvider
17621762
typename DocumentType::AllocatorType documentAllocator_;
17631763
typename SchemaDocumentType::AllocatorType schemaAllocator_;
17641764
char documentBuffer_[16384];
1765-
char schemaBuffer_[128 * 1024];
1765+
char schemaBuffer_[128u * 1024];
17661766
};
17671767

17681768
TEST(SchemaValidator, TestSuite) {

test/unittest/simdtest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ struct ScanCopyUnescapedStringHandler : BaseReaderHandler<UTF8<>, ScanCopyUnesca
109109

110110
template <unsigned parseFlags, typename StreamType>
111111
void TestScanCopyUnescapedString() {
112-
char buffer[1024 + 5 + 32];
113-
char backup[1024 + 5 + 32];
112+
char buffer[1024u + 5 + 32];
113+
char backup[1024u + 5 + 32];
114114

115115
// Test "ABCDABCD...\\"
116116
for (size_t offset = 0; offset < 32; offset++) {

0 commit comments

Comments
 (0)