Skip to content

Commit

Permalink
Merge pull request #43730 from qarmin/core_drivers_default_values
Browse files Browse the repository at this point in the history
Initialize class/struct variables with default values in core/ and drivers/
  • Loading branch information
akien-mga authored Nov 24, 2020
2 parents 4159baf + 7bd03b7 commit 32b31a5
Show file tree
Hide file tree
Showing 34 changed files with 221 additions and 228 deletions.
4 changes: 2 additions & 2 deletions core/core_bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -542,9 +542,9 @@ void _OS::dump_memory_to_file(const String &p_file) {
struct _OSCoreBindImg {
String path;
Size2 size;
int fmt;
int fmt = 0;
ObjectID id;
int vram;
int vram = 0;
bool operator<(const _OSCoreBindImg &p_img) const { return vram == p_img.vram ? id < p_img.id : vram > p_img.vram; }
};

Expand Down
4 changes: 2 additions & 2 deletions core/core_bind.h
Original file line number Diff line number Diff line change
Expand Up @@ -492,8 +492,8 @@ class _Directory : public Reference {
virtual ~_Directory();

private:
bool _list_skip_navigational;
bool _list_skip_hidden;
bool _list_skip_navigational = false;
bool _list_skip_hidden = false;
};

class _Marshalls : public Object {
Expand Down
4 changes: 2 additions & 2 deletions core/core_constants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@
struct _CoreConstant {
#ifdef DEBUG_METHODS_ENABLED
StringName enum_name;
bool ignore_value_in_docs;
bool ignore_value_in_docs = false;
#endif
const char *name;
int value;
int value = 0;

_CoreConstant() {}

Expand Down
1 change: 0 additions & 1 deletion core/crypto/aes_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,4 @@ void AESContext::_bind_methods() {
}

AESContext::AESContext() {
mode = MODE_MAX;
}
2 changes: 1 addition & 1 deletion core/crypto/aes_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class AESContext : public Reference {
};

private:
Mode mode;
Mode mode = MODE_MAX;
CryptoCore::AESContext ctx;
PackedByteArray iv;

Expand Down
8 changes: 4 additions & 4 deletions core/crypto/crypto_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class CryptoCore {
public:
class MD5Context {
private:
void *ctx; // To include, or not to include...
void *ctx = nullptr; // To include, or not to include...

public:
MD5Context();
Expand All @@ -50,7 +50,7 @@ class CryptoCore {

class SHA1Context {
private:
void *ctx; // To include, or not to include...
void *ctx = nullptr; // To include, or not to include...

public:
SHA1Context();
Expand All @@ -63,7 +63,7 @@ class CryptoCore {

class SHA256Context {
private:
void *ctx; // To include, or not to include...
void *ctx = nullptr; // To include, or not to include...

public:
SHA256Context();
Expand All @@ -76,7 +76,7 @@ class CryptoCore {

class AESContext {
private:
void *ctx; // To include, or not to include...
void *ctx = nullptr; // To include, or not to include...

public:
AESContext();
Expand Down
2 changes: 1 addition & 1 deletion core/crypto/hashing_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class HashingContext : public Reference {

private:
void *ctx = nullptr;
HashType type;
HashType type = HASH_MD5;

protected:
static void _bind_methods();
Expand Down
2 changes: 1 addition & 1 deletion core/debugger/debugger_marshalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ struct DebuggerMarshalls {

// Visual Profiler
struct VisualProfilerFrame {
uint64_t frame_number;
uint64_t frame_number = 0;
Vector<RS::FrameProfileArea> areas;

Array serialize();
Expand Down
4 changes: 2 additions & 2 deletions core/io/file_access_encrypted.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ class FileAccessEncrypted : public FileAccess {
Vector<uint8_t> key;
bool writing = false;
FileAccess *file = nullptr;
size_t base;
size_t length;
size_t base = 0;
size_t length = 0;
Vector<uint8_t> data;
mutable int pos = 0;
mutable bool eofed = false;
Expand Down
4 changes: 2 additions & 2 deletions core/io/file_access_memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@

class FileAccessMemory : public FileAccess {
uint8_t *data = nullptr;
int length;
mutable int pos;
int length = 0;
mutable int pos = 0;

static FileAccess *create();

Expand Down
2 changes: 1 addition & 1 deletion core/io/packed_data_container.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class PackedDataContainerRef : public Reference {
GDCLASS(PackedDataContainerRef, Reference);

friend class PackedDataContainer;
uint32_t offset;
uint32_t offset = 0;
Ref<PackedDataContainer> from;

protected:
Expand Down
8 changes: 4 additions & 4 deletions core/io/pck_packer.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class PCKPacker : public Reference {
GDCLASS(PCKPacker, Reference);

FileAccess *file = nullptr;
int alignment;
int alignment = 0;
uint64_t ofs = 0;

Vector<uint8_t> key;
Expand All @@ -50,9 +50,9 @@ class PCKPacker : public Reference {
struct File {
String path;
String src_path;
uint64_t ofs;
uint64_t size;
bool encrypted;
uint64_t ofs = 0;
uint64_t size = 0;
bool encrypted = false;
Vector<uint8_t> md5;
};
Vector<File> files;
Expand Down
16 changes: 8 additions & 8 deletions core/math/a_star.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,20 @@ class AStar : public Reference {
struct Point {
Point() {}

int id;
int id = 0;
Vector3 pos;
real_t weight_scale;
bool enabled;
real_t weight_scale = 0;
bool enabled = false;

OAHashMap<int, Point *> neighbours = 4u;
OAHashMap<int, Point *> unlinked_neighbours = 4u;

// Used for pathfinding.
Point *prev_point;
real_t g_score;
real_t f_score;
uint64_t open_pass;
uint64_t closed_pass;
Point *prev_point = nullptr;
real_t g_score = 0;
real_t f_score = 0;
uint64_t open_pass = 0;
uint64_t closed_pass = 0;
};

struct SortPoints {
Expand Down
22 changes: 11 additions & 11 deletions core/math/expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class Expression : public Reference {

ENode *next = nullptr;

Type type;
Type type = TYPE_INPUT;

ENode() {}
virtual ~ENode() {
Expand All @@ -144,7 +144,7 @@ class Expression : public Reference {
};

struct ExpressionNode {
bool is_op;
bool is_op = false;
union {
Variant::Operator op;
ENode *node;
Expand All @@ -154,23 +154,23 @@ class Expression : public Reference {
ENode *_parse_expression();

struct InputNode : public ENode {
int index;
int index = 0;
InputNode() {
type = TYPE_INPUT;
}
};

struct ConstantNode : public ENode {
Variant value;
Variant value = Variant::NIL;
ConstantNode() {
type = TYPE_CONSTANT;
}
};

struct OperatorNode : public ENode {
Variant::Operator op;
Variant::Operator op = Variant::Operator::OP_ADD;

ENode *nodes[2];
ENode *nodes[2] = { nullptr, nullptr };

OperatorNode() {
type = TYPE_OPERATOR;
Expand All @@ -184,16 +184,16 @@ class Expression : public Reference {
};

struct IndexNode : public ENode {
ENode *base;
ENode *index;
ENode *base = nullptr;
ENode *index = nullptr;

IndexNode() {
type = TYPE_INDEX;
}
};

struct NamedIndexNode : public ENode {
ENode *base;
ENode *base = nullptr;
StringName name;

NamedIndexNode() {
Expand All @@ -202,7 +202,7 @@ class Expression : public Reference {
};

struct ConstructorNode : public ENode {
Variant::Type data_type;
Variant::Type data_type = Variant::Type::NIL;
Vector<ENode *> arguments;

ConstructorNode() {
Expand All @@ -211,7 +211,7 @@ class Expression : public Reference {
};

struct CallNode : public ENode {
ENode *base;
ENode *base = nullptr;
StringName method;
Vector<ENode *> arguments;

Expand Down
10 changes: 6 additions & 4 deletions core/math/quick_hull.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class QuickHull {
struct Edge {
union {
uint32_t vertices[2];
uint64_t id;
uint64_t id = 0;
};

bool operator<(const Edge &p_edge) const {
Expand All @@ -60,7 +60,7 @@ class QuickHull {

struct Face {
Plane plane;
uint32_t vertices[3];
uint32_t vertices[3] = { 0 };
Vector<int> points_over;

bool operator<(const Face &p_face) const {
Expand All @@ -70,11 +70,13 @@ class QuickHull {

private:
struct FaceConnect {
List<Face>::Element *left, *right = nullptr;
List<Face>::Element *left = nullptr;
List<Face>::Element *right = nullptr;
FaceConnect() {}
};
struct RetFaceConnect {
List<Geometry3D::MeshData::Face>::Element *left, *right = nullptr;
List<Geometry3D::MeshData::Face>::Element *left = nullptr;
List<Geometry3D::MeshData::Face>::Element *right = nullptr;
RetFaceConnect() {}
};

Expand Down
1 change: 0 additions & 1 deletion core/os/dir_access.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ class DirAccess {
String _get_root_string() const;

String fix_path(String p_path) const;
bool next_is_dir;

template <class T>
static DirAccess *_create_builtin() {
Expand Down
4 changes: 2 additions & 2 deletions core/os/file_access.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ class CharBuffer {
Vector<char> vector;
char stack_buffer[256];

char *buffer;
int capacity;
char *buffer = nullptr;
int capacity = 0;
int written = 0;

bool grow() {
Expand Down
2 changes: 1 addition & 1 deletion core/templates/hash_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class HashMap {
private:
friend class HashMap;

uint32_t hash;
uint32_t hash = 0;
Element *next = nullptr;
Element() {}
Pair pair;
Expand Down
6 changes: 3 additions & 3 deletions core/templates/list.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ class List {

private:
struct _Data {
Element *first;
Element *last;
int size_cache;
Element *first = nullptr;
Element *last = nullptr;
int size_cache = 0;

bool erase(const Element *p_I) {
ERR_FAIL_COND_V(!p_I, false);
Expand Down
2 changes: 1 addition & 1 deletion core/templates/safe_refcount.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ uint64_t atomic_exchange_if_greater(volatile uint64_t *pw, volatile uint64_t val
#endif

struct SafeRefCount {
uint32_t count;
uint32_t count = 0;

public:
// destroy() is called when weak_count_ drops to zero.
Expand Down
2 changes: 1 addition & 1 deletion core/templates/set.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class Set {
private:
struct _Data {
Element *_root = nullptr;
Element *_nil;
Element *_nil = nullptr;
int size_cache = 0;

_FORCE_INLINE_ _Data() {
Expand Down
4 changes: 2 additions & 2 deletions core/templates/thread_work_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class ThreadWorkPool {
std::atomic<uint32_t> index;

struct BaseWork {
std::atomic<uint32_t> *index;
uint32_t max_elements;
std::atomic<uint32_t> *index = nullptr;
uint32_t max_elements = 0;
virtual void work() = 0;
virtual ~BaseWork() = default;
};
Expand Down
2 changes: 1 addition & 1 deletion core/variant/array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ void Array::sort() {
}

struct _ArrayVariantSortCustom {
Object *obj;
Object *obj = nullptr;
StringName func;

_FORCE_INLINE_ bool operator()(const Variant &p_l, const Variant &p_r) const {
Expand Down
6 changes: 3 additions & 3 deletions core/variant/callable.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ class Callable {
CALL_ERROR_TOO_FEW_ARGUMENTS, // expected is number of arguments
CALL_ERROR_INSTANCE_IS_NULL,
};
Error error;
int argument;
int expected;
Error error = Error::CALL_OK;
int argument = 0;
int expected = 0;
};

void call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, CallError &r_call_error) const;
Expand Down
Loading

0 comments on commit 32b31a5

Please sign in to comment.