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.
This commit is contained in:
Rémi Verschelde 2022-04-04 15:06:57 +02:00
parent 53317bbe14
commit f8ab79e68a
258 changed files with 2398 additions and 2421 deletions

View file

@ -40,7 +40,7 @@ class Engine {
public:
struct Singleton {
StringName name;
Object *ptr;
Object *ptr = nullptr;
StringName class_name; //used for binding generation hinting
bool user_created = false;
Singleton(const StringName &p_name = StringName(), Object *p_ptr = nullptr, const StringName &p_class_name = StringName());

View file

@ -447,7 +447,7 @@ public:
class Directory : public RefCounted {
GDCLASS(Directory, RefCounted);
DirAccess *d;
DirAccess *d = nullptr;
bool dir_open = false;
bool include_navigational = false;

View file

@ -183,7 +183,7 @@ struct FileAccessRef {
operator bool() const { return f != nullptr; }
FileAccess *f;
FileAccess *f = nullptr;
operator FileAccess *() { return f; }

View file

@ -64,7 +64,7 @@ public:
uint64_t offset; //if offset is ZERO, the file was ERASED
uint64_t size;
uint8_t md5[16];
PackSource *src;
PackSource *src = nullptr;
bool encrypted;
};
@ -103,7 +103,7 @@ private:
Vector<PackSource *> sources;
PackedDir *root;
PackedDir *root = nullptr;
static PackedData *singleton;
bool disabled = false;
@ -150,7 +150,7 @@ class FileAccessPack : public FileAccess {
mutable bool eof;
uint64_t off;
FileAccess *f;
FileAccess *f = nullptr;
virtual Error _open(const String &p_path, int p_mode_flags);
virtual uint64_t _get_modified_time(const String &p_file) { return 0; }
virtual uint32_t _get_unix_permissions(const String &p_file) { return 0; }

View file

@ -62,7 +62,7 @@ public:
typedef int ResolverID;
private:
_IP_ResolverPrivate *resolver;
_IP_ResolverPrivate *resolver = nullptr;
protected:
static IP *singleton;

View file

@ -127,7 +127,7 @@ class ResourceFormatSaverBinaryInstance {
bool skip_editor;
bool big_endian;
bool takeover_paths;
FileAccess *f;
FileAccess *f = nullptr;
String magic;
Set<RES> resource_set;

View file

@ -46,7 +46,7 @@ public:
static String get_cache_file();
private:
void *crypto; // CryptoCore::RandomGenerator (avoid including crypto_core.h)
void *crypto = nullptr; // CryptoCore::RandomGenerator (avoid including crypto_core.h)
Mutex mutex;
struct Cache {
CharString cs;

View file

@ -43,7 +43,7 @@ protected:
};
struct Peer {
PacketPeerUDP *peer;
PacketPeerUDP *peer = nullptr;
IPAddress ip;
uint16_t port = 0;

View file

@ -763,19 +763,19 @@ private:
tree._extra[p_handle.id()].last_updated_tick = 0;
}
PairCallback pair_callback;
UnpairCallback unpair_callback;
CheckPairCallback check_pair_callback;
void *pair_callback_userdata;
void *unpair_callback_userdata;
void *check_pair_callback_userdata;
PairCallback pair_callback = nullptr;
UnpairCallback unpair_callback = nullptr;
CheckPairCallback check_pair_callback = nullptr;
void *pair_callback_userdata = nullptr;
void *unpair_callback_userdata = nullptr;
void *check_pair_callback_userdata = nullptr;
BVHTREE_CLASS tree;
// for collision pairing,
// maintain a list of all items moved etc on each frame / tick
LocalVector<BVHHandle, uint32_t, true> changed_items;
uint32_t _tick;
uint32_t _tick = 1; // Start from 1 so items with 0 indicate never updated.
class BVHLockedFunction {
public:
@ -801,23 +801,16 @@ private:
}
private:
Mutex *_mutex;
Mutex *_mutex = nullptr;
};
Mutex _mutex;
// local toggle for turning on and off thread safety in project settings
bool _thread_safe;
bool _thread_safe = BVH_THREAD_SAFE;
public:
BVH_Manager() {
_tick = 1; // start from 1 so items with 0 indicate never updated
pair_callback = nullptr;
unpair_callback = nullptr;
pair_callback_userdata = nullptr;
unpair_callback_userdata = nullptr;
_thread_safe = BVH_THREAD_SAFE;
}
BVH_Manager() {}
};
#undef BVHTREE_CLASS

View file

@ -183,7 +183,7 @@ private:
Node *parent = nullptr;
union {
Node *childs[2];
void *data;
void *data = nullptr;
};
_FORCE_INLINE_ bool is_leaf() const { return childs[1] == nullptr; }
@ -215,10 +215,7 @@ private:
return axis.dot(volume.get_center() - org) <= 0;
}
Node() {
childs[0] = nullptr;
childs[1] = nullptr;
}
Node() {}
};
PagedAllocator<Node> node_allocator;

View file

@ -147,7 +147,7 @@ private:
bool is_op = false;
union {
Variant::Operator op;
ENode *node;
ENode *node = nullptr;
};
};

View file

@ -134,7 +134,7 @@ private:
List<PairData *, AL> pair_list;
struct OctantOwner {
Octant *octant;
Octant *octant = nullptr;
typename List<Element *, AL>::Element *E;
}; // an element can be in max 8 octants
@ -147,7 +147,7 @@ private:
int refcount;
bool intersect;
Element *A, *B;
void *ud;
void *ud = nullptr;
typename List<PairData *, AL>::Element *eA, *eB;
};
@ -156,18 +156,18 @@ private:
ElementMap element_map;
PairMap pair_map;
PairCallback pair_callback;
UnpairCallback unpair_callback;
void *pair_callback_userdata;
void *unpair_callback_userdata;
PairCallback pair_callback = nullptr;
UnpairCallback unpair_callback = nullptr;
void *pair_callback_userdata = nullptr;
void *unpair_callback_userdata = nullptr;
OctreeElementID last_element_id;
uint64_t pass;
OctreeElementID last_element_id = 1;
uint64_t pass = 1;
real_t unit_size;
Octant *root;
int octant_count;
int pair_count;
real_t unit_size = 1.0;
Octant *root = nullptr;
int octant_count = 0;
int pair_count = 0;
_FORCE_INLINE_ void _pair_check(PairData *p_pair) {
bool intersect = p_pair->A->aabb.intersects_inclusive(p_pair->B->aabb);
@ -294,7 +294,7 @@ private:
const Vector3 *points;
int point_count;
T **result_array;
int *result_idx;
int *result_idx = nullptr;
int result_max;
uint32_t mask;
};
@ -1265,18 +1265,7 @@ void Octree<T, use_pairs, AL>::set_unpair_callback(UnpairCallback p_callback, vo
template <class T, bool use_pairs, class AL>
Octree<T, use_pairs, AL>::Octree(real_t p_unit_size) {
last_element_id = 1;
pass = 1;
unit_size = p_unit_size;
root = nullptr;
octant_count = 0;
pair_count = 0;
pair_callback = nullptr;
unpair_callback = nullptr;
pair_callback_userdata = nullptr;
unpair_callback_userdata = nullptr;
}
#endif // OCTREE_H

View file

@ -38,7 +38,7 @@
#include "core/variant/callable.h"
class CallableCustomMethodPointerBase : public CallableCustom {
uint32_t *comp_ptr;
uint32_t *comp_ptr = nullptr;
uint32_t comp_size;
uint32_t h;
#ifdef DEBUG_METHODS_ENABLED

View file

@ -85,8 +85,8 @@ public:
int index;
StringName setter;
StringName getter;
MethodBind *_setptr;
MethodBind *_getptr;
MethodBind *_setptr = nullptr;
MethodBind *_getptr = nullptr;
Variant::Type type;
};

View file

@ -62,10 +62,10 @@ class MessageQueue {
};
};
uint8_t *buffer;
uint8_t *buffer = nullptr;
uint32_t buffer_end = 0;
uint32_t buffer_max_used = 0;
uint32_t buffer_size;
uint32_t buffer_size = 0;
void _call_function(const Callable &p_callable, const Variant *p_args, int p_argcount, bool p_show_error);

View file

@ -538,8 +538,8 @@ private:
std::mutex _instance_binding_mutex;
struct InstanceBinding {
void *binding;
void *token;
void *binding = nullptr;
void *token = nullptr;
GDNativeInstanceBindingFreeCallback free_callback = nullptr;
GDNativeInstanceBindingReferenceCallback reference_callback = nullptr;
};
@ -849,7 +849,7 @@ class ObjectDB {
uint64_t validator : OBJECTDB_VALIDATOR_BITS;
uint64_t next_free : OBJECTDB_SLOT_MAX_COUNT_BITS;
uint64_t is_ref_counted : 1;
Object *object;
Object *object = nullptr;
};
static SpinLock spin_lock;

View file

@ -430,11 +430,11 @@ public:
extern uint8_t script_encryption_key[32];
class PlaceHolderScriptInstance : public ScriptInstance {
Object *owner;
Object *owner = nullptr;
List<PropertyInfo> properties;
Map<StringName, Variant> values;
Map<StringName, Variant> constants;
ScriptLanguage *language;
ScriptLanguage *language = nullptr;
Ref<Script> script;
public:

View file

@ -186,9 +186,9 @@ void memdelete_arr(T *p_class) {
struct _GlobalNil {
int color = 1;
_GlobalNil *right;
_GlobalNil *left;
_GlobalNil *parent;
_GlobalNil *right = nullptr;
_GlobalNil *left = nullptr;
_GlobalNil *parent = nullptr;
_GlobalNil();
};

View file

@ -60,8 +60,6 @@ class OS {
bool _stdout_enabled = true;
bool _stderr_enabled = true;
char *last_error;
CompositeLogger *_logger = nullptr;
bool restart_on_exit = false;

View file

@ -75,13 +75,13 @@ private:
typedef int EntryArrayPos;
typedef int EntryIndicesPos;
Entry *entry_array;
int *entry_indices;
Entry *entry_array = nullptr;
int *entry_indices = nullptr;
int entry_max;
int entry_count;
uint8_t *pool;
void *mem_ptr;
uint8_t *pool = nullptr;
void *mem_ptr = nullptr;
int pool_size;
int free_mem;

View file

@ -70,7 +70,7 @@ class StringName {
_Data *_data = nullptr;
union _HashUnion {
_Data *ptr;
_Data *ptr = nullptr;
uint32_t hash;
};

View file

@ -311,7 +311,7 @@ class CommandQueueMT {
};
struct SyncCommand : public CommandBase {
SyncSemaphore *sync_sem;
SyncSemaphore *sync_sem = nullptr;
virtual void post() {
sync_sem->sem.post();

View file

@ -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;

View file

@ -306,7 +306,7 @@ public:
bool valid;
const TKey *key;
TValue *value;
TValue *value = nullptr;
private:
uint32_t pos;

View file

@ -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) :

View file

@ -108,7 +108,7 @@ public:
private:
List *_root = nullptr;
T *_self;
T *_self = nullptr;
SelfList<T> *_next = nullptr;
SelfList<T> *_prev = nullptr;

View file

@ -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;

View file

@ -68,7 +68,7 @@ class ThreadWorkPool {
Semaphore start;
Semaphore completed;
std::atomic<bool> exit;
BaseWork *work;
BaseWork *work = nullptr;
};
ThreadData *threads = nullptr;