diff options
author | Moonchild <mcwerewolf@gmail.com> | 2018-08-20 08:25:06 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-20 08:25:06 +0200 |
commit | 3499a2e4932e3054a229987aca80e7abd9c75c6c (patch) | |
tree | 1af747e97d275d0a47a0a8d75ce14e2b9f749fe0 | |
parent | 29fbe8f27d58a0dfa64aadbbd1757dbbeff3a4fd (diff) | |
parent | b5e87d0644f634240bf3c67cca505f91f271cfa9 (diff) | |
download | UXP-3499a2e4932e3054a229987aca80e7abd9c75c6c.tar UXP-3499a2e4932e3054a229987aca80e7abd9c75c6c.tar.gz UXP-3499a2e4932e3054a229987aca80e7abd9c75c6c.tar.lz UXP-3499a2e4932e3054a229987aca80e7abd9c75c6c.tar.xz UXP-3499a2e4932e3054a229987aca80e7abd9c75c6c.zip |
Merge pull request #714 from trav90/class-memaccess-errors
Fix more -Wclass-memaccess warnings:
- Avoid using memset on a not-trivial types
- Avoid doing memset on non-POD structures
- Be more restrictive with memset on Array containers
-rw-r--r-- | dom/bindings/BindingUtils.h | 2 | ||||
-rw-r--r-- | js/public/HashTable.h | 46 | ||||
-rw-r--r-- | js/public/MemoryMetrics.h | 18 | ||||
-rw-r--r-- | layout/base/nsArenaMemoryStats.h | 7 |
4 files changed, 56 insertions, 17 deletions
diff --git a/dom/bindings/BindingUtils.h b/dom/bindings/BindingUtils.h index 3e58390c9..24b47a545 100644 --- a/dom/bindings/BindingUtils.h +++ b/dom/bindings/BindingUtils.h @@ -515,7 +515,7 @@ class ProtoAndIfaceCache { public: PageTableCache() { - memset(&mPages, 0, sizeof(mPages)); + memset(mPages.begin(), 0, sizeof(mPages)); } ~PageTableCache() { diff --git a/js/public/HashTable.h b/js/public/HashTable.h index 5d4c0665d..8a2493b55 100644 --- a/js/public/HashTable.h +++ b/js/public/HashTable.h @@ -12,6 +12,7 @@ #include "mozilla/Attributes.h" #include "mozilla/Casting.h" #include "mozilla/HashFunctions.h" +#include "mozilla/MemoryChecking.h" #include "mozilla/MemoryReporting.h" #include "mozilla/Move.h" #include "mozilla/Opaque.h" @@ -805,17 +806,22 @@ class HashTableEntry void operator=(const HashTableEntry&) = delete; ~HashTableEntry() = delete; + void destroyStoredT() { + mem.addr()->~T(); + MOZ_MAKE_MEM_UNDEFINED(mem.addr(), sizeof(*mem.addr())); + } + public: // NB: HashTableEntry is treated as a POD: no constructor or destructor calls. void destroyIfLive() { if (isLive()) - mem.addr()->~T(); + destroyStoredT(); } void destroy() { MOZ_ASSERT(isLive()); - mem.addr()->~T(); + destroyStoredT(); } void swap(HashTableEntry* other) { @@ -835,10 +841,28 @@ class HashTableEntry NonConstT& getMutable() { MOZ_ASSERT(isLive()); return *mem.addr(); } bool isFree() const { return keyHash == sFreeKey; } - void clearLive() { MOZ_ASSERT(isLive()); keyHash = sFreeKey; mem.addr()->~T(); } - void clear() { if (isLive()) mem.addr()->~T(); keyHash = sFreeKey; } + void clearLive() { + MOZ_ASSERT(isLive()); + keyHash = sFreeKey; + destroyStoredT(); + } + + void clear() { + if (isLive()) + destroyStoredT(); + + MOZ_MAKE_MEM_UNDEFINED(this, sizeof(*this)); + keyHash = sFreeKey; + } + bool isRemoved() const { return keyHash == sRemovedKey; } - void removeLive() { MOZ_ASSERT(isLive()); keyHash = sRemovedKey; mem.addr()->~T(); } + + void removeLive() { + MOZ_ASSERT(isLive()); + keyHash = sRemovedKey; + destroyStoredT(); + } + bool isLive() const { return isLiveHash(keyHash); } void setCollision() { MOZ_ASSERT(isLive()); keyHash |= sCollisionBit; } void unsetCollision() { keyHash &= ~sCollisionBit; } @@ -1654,14 +1678,10 @@ class HashTable : private AllocPolicy public: void clear() { - if (mozilla::IsPod<Entry>::value) { - memset(table, 0, sizeof(*table) * capacity()); - } else { - uint32_t tableCapacity = capacity(); - Entry* end = table + tableCapacity; - for (Entry* e = table; e < end; ++e) - e->clear(); - } + Entry* end = table + capacity(); + for (Entry* e = table; e < end; ++e) + e->clear(); + removedCount = 0; entryCount = 0; #ifdef JS_DEBUG diff --git a/js/public/MemoryMetrics.h b/js/public/MemoryMetrics.h index 9b5caa24b..b0b26631c 100644 --- a/js/public/MemoryMetrics.h +++ b/js/public/MemoryMetrics.h @@ -37,7 +37,13 @@ struct TabSizes Other }; - TabSizes() { mozilla::PodZero(this); } + TabSizes() + : objects(0) + , strings(0) + , private_(0) + , other(0) + { + } void add(Kind kind, size_t n) { switch (kind) { @@ -68,7 +74,15 @@ struct ServoSizes Ignore }; - ServoSizes() { mozilla::PodZero(this); } + ServoSizes() + : gcHeapUsed(0) + , gcHeapUnused(0) + , gcHeapAdmin(0) + , gcHeapDecommitted(0) + , mallocHeap(0) + , nonHeap(0) + { + } void add(Kind kind, size_t n) { switch (kind) { diff --git a/layout/base/nsArenaMemoryStats.h b/layout/base/nsArenaMemoryStats.h index ba09baaa4..2a872cfe8 100644 --- a/layout/base/nsArenaMemoryStats.h +++ b/layout/base/nsArenaMemoryStats.h @@ -18,7 +18,12 @@ public: Other // Everything else. }; - nsTabSizes() { mozilla::PodZero(this); } + nsTabSizes() + : mDom(0) + , mStyle(0) + , mOther(0) + { + } void add(Kind kind, size_t n) { |