Commit 5b58f6b0 authored by Alexander Gerasiov's avatar Alexander Gerasiov

Add patches to deal with gcc 8.0 errors. Fixes FTBFS (Closes: #906406)

0001-Fix-Wclass-memaccess-warnings-errors.patch
0002-Fix-Wsign-conversion-warnings-errors.patch
0003-Suppress-Wformat-overflow-warning-error.patch
Signed-off-by: Alexander Gerasiov's avatarAlexander GQ Gerasiov <gq@cs.msu.su>
parent 4a48ebfe
From fa5963a2f5b231ee2babff771f169ccca22870ed Mon Sep 17 00:00:00 2001
From: Philipp A Hartmann <pah@qo.cx>
Date: Sun, 15 Jul 2018 14:17:14 +0200
Subject: [PATCH 1/3] Fix -Wclass-memaccess warnings/errors
Recent GCC versions warn about using memcpy/memmove to
write to a class pointer (-Wclass-memaccess).
Avoid the warnings by casting to void* first.
Closes #1086.
Closes #1205.
Closes #1246.
---
include/rapidjson/document.h | 20 +++++---------------
1 file changed, 5 insertions(+), 15 deletions(-)
--- a/include/rapidjson/document.h
+++ b/include/rapidjson/document.h
@@ -1425,7 +1425,7 @@
MemberIterator pos = MemberBegin() + (first - MemberBegin());
for (MemberIterator itr = pos; itr != last; ++itr)
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);
return pos;
}
@@ -1628,8 +1628,8 @@
RAPIDJSON_ASSERT(last <= End());
ValueIterator pos = Begin() + (first - Begin());
for (ValueIterator itr = pos; itr != last; ++itr)
- itr->~GenericValue();
- std::memmove(pos, last, static_cast<size_t>(End() - last) * sizeof(GenericValue));
+ itr->~GenericValue();
+ std::memmove(static_cast<void*>(pos), last, static_cast<size_t>(End() - last) * sizeof(GenericValue));
data_.a.size -= static_cast<SizeType>(last - first);
return pos;
}
@@ -1936,7 +1936,7 @@
if (count) {
GenericValue* e = static_cast<GenericValue*>(allocator.Malloc(count * sizeof(GenericValue)));
SetElementsPointer(e);
- std::memcpy(e, values, count * sizeof(GenericValue));
+ std::memcpy(static_cast<void*>(e), values, count * sizeof(GenericValue));
}
else
SetElementsPointer(0);
@@ -1949,7 +1949,7 @@
if (count) {
Member* m = static_cast<Member*>(allocator.Malloc(count * sizeof(Member)));
SetMembersPointer(m);
- std::memcpy(m, members, count * sizeof(Member));
+ std::memcpy(static_cast<void*>(m), members, count * sizeof(Member));
}
else
SetMembersPointer(0);
From a26267d16dcdc22a15722917a51dc50cdc8aaac0 Mon Sep 17 00:00:00 2001
From: Philipp A Hartmann <pah@qo.cx>
Date: Sun, 15 Jul 2018 16:01:02 +0200
Subject: [PATCH 2/3] Fix -Wsign-conversion warnings/errors
GCC 8 (incorrectly) warns about sign conversions in (constant)
array size expressions:
error: conversion to 'long unsigned int' from 'int' may
change the sign of the result [-Werror=sign-conversion]
char schemaBuffer_[128 * 1024];
Make these expressions unsigned by adding a 'u' suffix to
the first operands.
---
include/rapidjson/schema.h | 2 +-
test/unittest/schematest.cpp | 2 +-
test/unittest/simdtest.cpp | 4 ++--
3 files changed, 4 insertions(+), 4 deletions(-)
--- a/include/rapidjson/schema.h
+++ b/include/rapidjson/schema.h
@@ -400,7 +400,7 @@
enum_ = static_cast<uint64_t*>(allocator_->Malloc(sizeof(uint64_t) * v->Size()));
for (ConstValueIterator itr = v->Begin(); itr != v->End(); ++itr) {
typedef Hasher<EncodingType, MemoryPoolAllocator<> > EnumHasherType;
- char buffer[256 + 24];
+ char buffer[256u + 24];
MemoryPoolAllocator<> hasherAllocator(buffer, sizeof(buffer));
EnumHasherType h(&hasherAllocator, 256);
itr->Accept(h);
--- a/test/unittest/schematest.cpp
+++ b/test/unittest/schematest.cpp
@@ -1117,7 +1117,7 @@
typename DocumentType::AllocatorType documentAllocator_;
typename SchemaDocumentType::AllocatorType schemaAllocator_;
char documentBuffer_[16384];
- char schemaBuffer_[128 * 1024];
+ char schemaBuffer_[128u * 1024];
};
TEST(SchemaValidator, TestSuite) {
--- a/test/unittest/simdtest.cpp
+++ b/test/unittest/simdtest.cpp
@@ -105,8 +105,8 @@
template <unsigned parseFlags, typename StreamType>
void TestScanCopyUnescapedString() {
- char buffer[1024 + 5 + 32];
- char backup[1024 + 5 + 32];
+ char buffer[1024u + 5 + 32];
+ char backup[1024u + 5 + 32];
// Test "ABCDABCD...\\"
for (size_t offset = 0; offset < 32; offset++) {
From 152511689bd9b9cdeed6a580479698e13df056b6 Mon Sep 17 00:00:00 2001
From: Philipp A Hartmann <pah@qo.cx>
Date: Sun, 15 Jul 2018 16:02:03 +0200
Subject: [PATCH 3/3] Suppress -Wformat-overflow warning/error
GCC 7 and later warn about overflow/truncation when using
sprintf and related functions with fixed-size buffers.
Suppress the warning in schematest.cpp.
---
test/perftest/schematest.cpp | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/test/perftest/schematest.cpp b/test/perftest/schematest.cpp
index 468f5fe6..7d27344b 100644
--- a/test/perftest/schematest.cpp
+++ b/test/perftest/schematest.cpp
@@ -11,6 +11,11 @@
using namespace rapidjson;
+RAPIDJSON_DIAG_PUSH
+#if defined(__GNUC__) && __GNUC__ >= 7
+RAPIDJSON_DIAG_OFF(format-overflow)
+#endif
+
template <typename Allocator>
static char* ReadFile(const char* filename, Allocator& allocator) {
const char *paths[] = {
@@ -42,6 +47,8 @@ static char* ReadFile(const char* filename, Allocator& allocator) {
return json;
}
+RAPIDJSON_DIAG_POP
+
class Schema : public PerfTest {
public:
Schema() {}
--
2.18.0
......@@ -2,3 +2,6 @@ set-doc-dir.diff
disable-valgrind_unittest.diff
no-jsoncheckertest.diff
gcc7.diff
0001-Fix-Wclass-memaccess-warnings-errors.patch
0002-Fix-Wsign-conversion-warnings-errors.patch
0003-Suppress-Wformat-overflow-warning-error.patch
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