Unverified Commit 2bbd33b3 authored by Milo Yip's avatar Milo Yip Committed by GitHub

Merge pull request #1323 from pah/fix-memaccess

Fix warnings/errors on GCC 7/8 (-Wclass-memaccess, -Wsign-conversion, -Wformat-overflow) 
parents 4b4583bd 15251168
...@@ -1513,7 +1513,7 @@ public: ...@@ -1513,7 +1513,7 @@ public:
MemberIterator pos = MemberBegin() + (first - MemberBegin()); MemberIterator pos = MemberBegin() + (first - MemberBegin());
for (MemberIterator itr = pos; itr != last; ++itr) for (MemberIterator itr = pos; itr != last; ++itr)
itr->~Member(); itr->~Member();
std::memmove(&*pos, &*last, static_cast<size_t>(MemberEnd() - last) * sizeof(Member)); std::memmove(static_cast<void*>(&*pos), &*last, static_cast<size_t>(MemberEnd() - last) * sizeof(Member));
data_.o.size -= static_cast<SizeType>(last - first); data_.o.size -= static_cast<SizeType>(last - first);
return pos; return pos;
} }
...@@ -1716,8 +1716,8 @@ public: ...@@ -1716,8 +1716,8 @@ public:
RAPIDJSON_ASSERT(last <= End()); RAPIDJSON_ASSERT(last <= End());
ValueIterator pos = Begin() + (first - Begin()); ValueIterator pos = Begin() + (first - Begin());
for (ValueIterator itr = pos; itr != last; ++itr) for (ValueIterator itr = pos; itr != last; ++itr)
itr->~GenericValue(); itr->~GenericValue();
std::memmove(pos, last, static_cast<size_t>(End() - last) * sizeof(GenericValue)); std::memmove(static_cast<void*>(pos), last, static_cast<size_t>(End() - last) * sizeof(GenericValue));
data_.a.size -= static_cast<SizeType>(last - first); data_.a.size -= static_cast<SizeType>(last - first);
return pos; return pos;
} }
...@@ -2032,12 +2032,7 @@ private: ...@@ -2032,12 +2032,7 @@ private:
if (count) { if (count) {
GenericValue* e = static_cast<GenericValue*>(allocator.Malloc(count * sizeof(GenericValue))); GenericValue* e = static_cast<GenericValue*>(allocator.Malloc(count * sizeof(GenericValue)));
SetElementsPointer(e); SetElementsPointer(e);
RAPIDJSON_DIAG_PUSH std::memcpy(static_cast<void*>(e), values, count * sizeof(GenericValue));
#if defined(__GNUC__) && __GNUC__ >= 8
RAPIDJSON_DIAG_OFF(class-memaccess) // ignore complains from gcc that no trivial copy constructor exists.
#endif
std::memcpy(e, values, count * sizeof(GenericValue));
RAPIDJSON_DIAG_POP
} }
else else
SetElementsPointer(0); SetElementsPointer(0);
...@@ -2050,12 +2045,7 @@ RAPIDJSON_DIAG_POP ...@@ -2050,12 +2045,7 @@ RAPIDJSON_DIAG_POP
if (count) { if (count) {
Member* m = static_cast<Member*>(allocator.Malloc(count * sizeof(Member))); Member* m = static_cast<Member*>(allocator.Malloc(count * sizeof(Member)));
SetMembersPointer(m); SetMembersPointer(m);
RAPIDJSON_DIAG_PUSH std::memcpy(static_cast<void*>(m), members, count * sizeof(Member));
#if defined(__GNUC__) && __GNUC__ >= 8
RAPIDJSON_DIAG_OFF(class-memaccess) // ignore complains from gcc that no trivial copy constructor exists.
#endif
std::memcpy(m, members, count * sizeof(Member));
RAPIDJSON_DIAG_POP
} }
else else
SetMembersPointer(0); SetMembersPointer(0);
......
...@@ -464,7 +464,7 @@ public: ...@@ -464,7 +464,7 @@ public:
enum_ = static_cast<uint64_t*>(allocator_->Malloc(sizeof(uint64_t) * v->Size())); enum_ = static_cast<uint64_t*>(allocator_->Malloc(sizeof(uint64_t) * v->Size()));
for (ConstValueIterator itr = v->Begin(); itr != v->End(); ++itr) { for (ConstValueIterator itr = v->Begin(); itr != v->End(); ++itr) {
typedef Hasher<EncodingType, MemoryPoolAllocator<> > EnumHasherType; typedef Hasher<EncodingType, MemoryPoolAllocator<> > EnumHasherType;
char buffer[256 + 24]; char buffer[256u + 24];
MemoryPoolAllocator<> hasherAllocator(buffer, sizeof(buffer)); MemoryPoolAllocator<> hasherAllocator(buffer, sizeof(buffer));
EnumHasherType h(&hasherAllocator, 256); EnumHasherType h(&hasherAllocator, 256);
itr->Accept(h); itr->Accept(h);
......
...@@ -11,6 +11,11 @@ ...@@ -11,6 +11,11 @@
using namespace rapidjson; using namespace rapidjson;
RAPIDJSON_DIAG_PUSH
#if defined(__GNUC__) && __GNUC__ >= 7
RAPIDJSON_DIAG_OFF(format-overflow)
#endif
template <typename Allocator> template <typename Allocator>
static char* ReadFile(const char* filename, Allocator& allocator) { static char* ReadFile(const char* filename, Allocator& allocator) {
const char *paths[] = { const char *paths[] = {
...@@ -42,6 +47,8 @@ static char* ReadFile(const char* filename, Allocator& allocator) { ...@@ -42,6 +47,8 @@ static char* ReadFile(const char* filename, Allocator& allocator) {
return json; return json;
} }
RAPIDJSON_DIAG_POP
class Schema : public PerfTest { class Schema : public PerfTest {
public: public:
Schema() {} Schema() {}
......
...@@ -1762,7 +1762,7 @@ private: ...@@ -1762,7 +1762,7 @@ private:
typename DocumentType::AllocatorType documentAllocator_; typename DocumentType::AllocatorType documentAllocator_;
typename SchemaDocumentType::AllocatorType schemaAllocator_; typename SchemaDocumentType::AllocatorType schemaAllocator_;
char documentBuffer_[16384]; char documentBuffer_[16384];
char schemaBuffer_[128 * 1024]; char schemaBuffer_[128u * 1024];
}; };
TEST(SchemaValidator, TestSuite) { TEST(SchemaValidator, TestSuite) {
......
...@@ -109,8 +109,8 @@ struct ScanCopyUnescapedStringHandler : BaseReaderHandler<UTF8<>, ScanCopyUnesca ...@@ -109,8 +109,8 @@ struct ScanCopyUnescapedStringHandler : BaseReaderHandler<UTF8<>, ScanCopyUnesca
template <unsigned parseFlags, typename StreamType> template <unsigned parseFlags, typename StreamType>
void TestScanCopyUnescapedString() { void TestScanCopyUnescapedString() {
char buffer[1024 + 5 + 32]; char buffer[1024u + 5 + 32];
char backup[1024 + 5 + 32]; char backup[1024u + 5 + 32];
// Test "ABCDABCD...\\" // Test "ABCDABCD...\\"
for (size_t offset = 0; offset < 32; offset++) { for (size_t offset = 0; offset < 32; offset++) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment