From f8ab79e68af20e18e1d868b64d6dfd0c429bc554 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Mon, 4 Apr 2022 15:06:57 +0200 Subject: Zero initialize all pointer class and struct members This prevents the pitfall of UB when checking if they have been assigned something valid by comparing to nullptr. --- core/templates/command_queue_mt.h | 2 +- core/templates/map.h | 6 +++--- core/templates/oa_hash_map.h | 2 +- core/templates/safe_list.h | 8 ++++---- core/templates/self_list.h | 2 +- core/templates/set.h | 4 ++-- core/templates/thread_work_pool.h | 2 +- 7 files changed, 13 insertions(+), 13 deletions(-) (limited to 'core/templates') diff --git a/core/templates/command_queue_mt.h b/core/templates/command_queue_mt.h index 1ecb81c2a2..0aa1cfd541 100644 --- a/core/templates/command_queue_mt.h +++ b/core/templates/command_queue_mt.h @@ -311,7 +311,7 @@ class CommandQueueMT { }; struct SyncCommand : public CommandBase { - SyncSemaphore *sync_sem; + SyncSemaphore *sync_sem = nullptr; virtual void post() { sync_sem->sem.post(); diff --git a/core/templates/map.h b/core/templates/map.h index f228640a1e..c54da1dc03 100644 --- a/core/templates/map.h +++ b/core/templates/map.h @@ -178,7 +178,7 @@ public: private: struct _Data { Element *_root = nullptr; - Element *_nil; + Element *_nil = nullptr; int size_cache = 0; _FORCE_INLINE_ _Data() { @@ -344,7 +344,7 @@ private: void _insert_rb_fix(Element *p_new_node) { Element *node = p_new_node; Element *nparent = node->parent; - Element *ngrand_parent; + Element *ngrand_parent = nullptr; while (nparent->color == RED) { ngrand_parent = nparent->parent; @@ -500,7 +500,7 @@ private: Element *rp = ((p_node->left == _data._nil) || (p_node->right == _data._nil)) ? p_node : p_node->_next; Element *node = (rp->left == _data._nil) ? rp->right : rp->left; - Element *sibling; + Element *sibling = nullptr; if (rp == rp->parent->left) { rp->parent->left = node; sibling = rp->parent->right; diff --git a/core/templates/oa_hash_map.h b/core/templates/oa_hash_map.h index 4e712fccf2..e4d9323c45 100644 --- a/core/templates/oa_hash_map.h +++ b/core/templates/oa_hash_map.h @@ -306,7 +306,7 @@ public: bool valid; const TKey *key; - TValue *value; + TValue *value = nullptr; private: uint32_t pos; diff --git a/core/templates/safe_list.h b/core/templates/safe_list.h index 53fc3fe5f9..ae31525dd0 100644 --- a/core/templates/safe_list.h +++ b/core/templates/safe_list.h @@ -75,8 +75,8 @@ public: class Iterator { friend class SafeList; - SafeListNode *cursor; - SafeList *list; + SafeListNode *cursor = nullptr; + SafeList *list = nullptr; Iterator(SafeListNode *p_cursor, SafeList *p_list) : cursor(p_cursor), list(p_list) { @@ -253,8 +253,8 @@ public: class Iterator { friend class SafeList; - SafeListNode *cursor; - SafeList *list; + SafeListNode *cursor = nullptr; + SafeList *list = nullptr; public: Iterator(SafeListNode *p_cursor, SafeList *p_list) : diff --git a/core/templates/self_list.h b/core/templates/self_list.h index 7f2236fa3a..719b5f2e63 100644 --- a/core/templates/self_list.h +++ b/core/templates/self_list.h @@ -108,7 +108,7 @@ public: private: List *_root = nullptr; - T *_self; + T *_self = nullptr; SelfList *_next = nullptr; SelfList *_prev = nullptr; diff --git a/core/templates/set.h b/core/templates/set.h index cdc6e8447d..a8a0a77712 100644 --- a/core/templates/set.h +++ b/core/templates/set.h @@ -328,7 +328,7 @@ private: void _insert_rb_fix(Element *p_new_node) { Element *node = p_new_node; Element *nparent = node->parent; - Element *ngrand_parent; + Element *ngrand_parent = nullptr; while (nparent->color == RED) { ngrand_parent = nparent->parent; @@ -482,7 +482,7 @@ private: Element *rp = ((p_node->left == _data._nil) || (p_node->right == _data._nil)) ? p_node : p_node->_next; Element *node = (rp->left == _data._nil) ? rp->right : rp->left; - Element *sibling; + Element *sibling = nullptr; if (rp == rp->parent->left) { rp->parent->left = node; sibling = rp->parent->right; diff --git a/core/templates/thread_work_pool.h b/core/templates/thread_work_pool.h index 957af44f48..d364ac4fd8 100644 --- a/core/templates/thread_work_pool.h +++ b/core/templates/thread_work_pool.h @@ -68,7 +68,7 @@ class ThreadWorkPool { Semaphore start; Semaphore completed; std::atomic exit; - BaseWork *work; + BaseWork *work = nullptr; }; ThreadData *threads = nullptr; -- cgit v1.2.3