File: 0001-Fix-Wclass-memaccess-warnings-errors.patch

package info (click to toggle)
rapidjson 1.1.0%2Bdfsg2-7.6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,264 kB
  • sloc: cpp: 18,852; ansic: 2,434; python: 235; xml: 182; sh: 83; makefile: 10; javascript: 2
file content (57 lines) | stat: -rw-r--r-- 2,388 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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);