Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Core] Replace ERR_FAIL_COND with ERR_FAIL_NULL where applicable #81487

Merged
merged 1 commit into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/crypto/crypto_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Error CryptoCore::RandomGenerator::init() {
}

Error CryptoCore::RandomGenerator::get_random_bytes(uint8_t *r_buffer, size_t p_bytes) {
ERR_FAIL_COND_V(!ctx, ERR_UNCONFIGURED);
ERR_FAIL_NULL_V(ctx, ERR_UNCONFIGURED);
int ret = mbedtls_ctr_drbg_random((mbedtls_ctr_drbg_context *)ctx, r_buffer, p_bytes);
ERR_FAIL_COND_V_MSG(ret, FAILED, " failed\n ! mbedtls_ctr_drbg_seed returned an error" + itos(ret));
return OK;
Expand Down
6 changes: 3 additions & 3 deletions core/crypto/hashing_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
Error HashingContext::start(HashType p_type) {
ERR_FAIL_COND_V(ctx != nullptr, ERR_ALREADY_IN_USE);
_create_ctx(p_type);
ERR_FAIL_COND_V(ctx == nullptr, ERR_UNAVAILABLE);
ERR_FAIL_NULL_V(ctx, ERR_UNAVAILABLE);
switch (type) {
case HASH_MD5:
return ((CryptoCore::MD5Context *)ctx)->start();
Expand All @@ -48,7 +48,7 @@ Error HashingContext::start(HashType p_type) {
}

Error HashingContext::update(PackedByteArray p_chunk) {
ERR_FAIL_COND_V(ctx == nullptr, ERR_UNCONFIGURED);
ERR_FAIL_NULL_V(ctx, ERR_UNCONFIGURED);
size_t len = p_chunk.size();
ERR_FAIL_COND_V(len == 0, FAILED);
const uint8_t *r = p_chunk.ptr();
Expand All @@ -64,7 +64,7 @@ Error HashingContext::update(PackedByteArray p_chunk) {
}

PackedByteArray HashingContext::finish() {
ERR_FAIL_COND_V(ctx == nullptr, PackedByteArray());
ERR_FAIL_NULL_V(ctx, PackedByteArray());
PackedByteArray out;
Error err = FAILED;
switch (type) {
Expand Down
4 changes: 2 additions & 2 deletions core/debugger/remote_debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ void RemoteDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) {
Array msg;
msg.push_back(p_can_continue);
msg.push_back(error_str);
ERR_FAIL_COND(!script_lang);
ERR_FAIL_NULL(script_lang);
msg.push_back(script_lang->debug_get_stack_level_count() > 0);
msg.push_back(Thread::get_caller_id() == Thread::get_main_id() ? String(RTR("Main Thread")) : itos(Thread::get_caller_id()));
if (allow_focus_steal_fn) {
Expand Down Expand Up @@ -485,7 +485,7 @@ void RemoteDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) {

} else if (command == "get_stack_frame_vars") {
ERR_FAIL_COND(data.size() != 1);
ERR_FAIL_COND(!script_lang);
ERR_FAIL_NULL(script_lang);
int lv = data[0];

List<String> members;
Expand Down
10 changes: 5 additions & 5 deletions core/extension/gdextension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ void GDExtension::register_interface_function(StringName p_function_name, GDExte

GDExtensionInterfaceFunctionPtr GDExtension::get_interface_function(StringName p_function_name) {
GDExtensionInterfaceFunctionPtr *function = gdextension_interface_functions.getptr(p_function_name);
ERR_FAIL_COND_V_MSG(function == nullptr, nullptr, "Attempt to get non-existent interface function: " + p_function_name);
ERR_FAIL_NULL_V_MSG(function, nullptr, "Attempt to get non-existent interface function: " + String(p_function_name) + ".");
return *function;
}

Expand Down Expand Up @@ -525,7 +525,7 @@ Error GDExtension::open_library(const String &p_path, const String &p_entry_symb
}

void GDExtension::close_library() {
ERR_FAIL_COND(library == nullptr);
ERR_FAIL_NULL(library);
OS::get_singleton()->close_dynamic_library(library);

#if defined(TOOLS_ENABLED) && defined(WINDOWS_ENABLED)
Expand All @@ -543,12 +543,12 @@ bool GDExtension::is_library_open() const {
}

GDExtension::InitializationLevel GDExtension::get_minimum_library_initialization_level() const {
ERR_FAIL_COND_V(library == nullptr, INITIALIZATION_LEVEL_CORE);
ERR_FAIL_NULL_V(library, INITIALIZATION_LEVEL_CORE);
return InitializationLevel(initialization.minimum_initialization_level);
}

void GDExtension::initialize_library(InitializationLevel p_level) {
ERR_FAIL_COND(library == nullptr);
ERR_FAIL_NULL(library);
ERR_FAIL_COND_MSG(p_level <= int32_t(level_initialized), vformat("Level '%d' must be higher than the current level '%d'", p_level, level_initialized));

level_initialized = int32_t(p_level);
Expand All @@ -558,7 +558,7 @@ void GDExtension::initialize_library(InitializationLevel p_level) {
initialization.initialize(initialization.userdata, GDExtensionInitializationLevel(p_level));
}
void GDExtension::deinitialize_library(InitializationLevel p_level) {
ERR_FAIL_COND(library == nullptr);
ERR_FAIL_NULL(library);
ERR_FAIL_COND(p_level > int32_t(level_initialized));

level_initialized = int32_t(p_level) - 1;
Expand Down
4 changes: 2 additions & 2 deletions core/extension/gdextension_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,7 @@ static GDExtensionScriptInstancePtr gdextension_placeholder_script_instance_crea

static void gdextension_placeholder_script_instance_update(GDExtensionScriptInstancePtr p_placeholder, GDExtensionConstTypePtr p_properties, GDExtensionConstTypePtr p_values) {
PlaceHolderScriptInstance *placeholder = dynamic_cast<PlaceHolderScriptInstance *>(reinterpret_cast<ScriptInstance *>(p_placeholder));
ERR_FAIL_COND_MSG(!placeholder, "Unable to update placeholder, expected a PlaceHolderScriptInstance but received an invalid type.");
ERR_FAIL_NULL_MSG(placeholder, "Unable to update placeholder, expected a PlaceHolderScriptInstance but received an invalid type.");

const Array &properties = *reinterpret_cast<const Array *>(p_properties);
const Dictionary &values = *reinterpret_cast<const Dictionary *>(p_values);
Expand Down Expand Up @@ -1148,7 +1148,7 @@ static GDExtensionMethodBindPtr gdextension_classdb_get_method_bind(GDExtensionC
ERR_PRINT("Method '" + classname + "." + methodname + "' has changed and no compatibility fallback has been provided. Please open an issue.");
return nullptr;
}
ERR_FAIL_COND_V(!mb, nullptr);
ERR_FAIL_NULL_V(mb, nullptr);
if (mb->get_hash() != p_hash) {
ERR_PRINT("Hash mismatch for method '" + classname + "." + methodname + "'.");
return nullptr;
Expand Down
2 changes: 1 addition & 1 deletion core/io/compression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ int Compression::decompress_dynamic(Vector<uint8_t> *p_dst_vect, int p_max_dst_s
#ifdef BROTLI_ENABLED
BrotliDecoderResult ret;
BrotliDecoderState *state = BrotliDecoderCreateInstance(nullptr, nullptr, nullptr);
ERR_FAIL_COND_V(state == nullptr, Z_DATA_ERROR);
ERR_FAIL_NULL_V(state, Z_DATA_ERROR);

// Setup the stream inputs.
const uint8_t *next_in = p_src;
Expand Down
16 changes: 8 additions & 8 deletions core/io/file_access_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Error FileAccessMemory::open_custom(const uint8_t *p_data, uint64_t p_len) {
}

Error FileAccessMemory::open_internal(const String &p_path, int p_mode_flags) {
ERR_FAIL_COND_V(!files, ERR_FILE_NOT_FOUND);
ERR_FAIL_NULL_V(files, ERR_FILE_NOT_FOUND);

String name = fix_path(p_path);
//name = DirAccess::normalize_path(name);
Expand All @@ -99,22 +99,22 @@ bool FileAccessMemory::is_open() const {
}

void FileAccessMemory::seek(uint64_t p_position) {
ERR_FAIL_COND(!data);
ERR_FAIL_NULL(data);
pos = p_position;
}

void FileAccessMemory::seek_end(int64_t p_position) {
ERR_FAIL_COND(!data);
ERR_FAIL_NULL(data);
pos = length + p_position;
}

uint64_t FileAccessMemory::get_position() const {
ERR_FAIL_COND_V(!data, 0);
ERR_FAIL_NULL_V(data, 0);
return pos;
}

uint64_t FileAccessMemory::get_length() const {
ERR_FAIL_COND_V(!data, 0);
ERR_FAIL_NULL_V(data, 0);
return length;
}

Expand All @@ -134,7 +134,7 @@ uint8_t FileAccessMemory::get_8() const {

uint64_t FileAccessMemory::get_buffer(uint8_t *p_dst, uint64_t p_length) const {
ERR_FAIL_COND_V(!p_dst && p_length > 0, -1);
ERR_FAIL_COND_V(!data, -1);
ERR_FAIL_NULL_V(data, -1);

uint64_t left = length - pos;
uint64_t read = MIN(p_length, left);
Expand All @@ -154,11 +154,11 @@ Error FileAccessMemory::get_error() const {
}

void FileAccessMemory::flush() {
ERR_FAIL_COND(!data);
ERR_FAIL_NULL(data);
}

void FileAccessMemory::store_8(uint8_t p_byte) {
ERR_FAIL_COND(!data);
ERR_FAIL_NULL(data);
ERR_FAIL_COND(pos >= length);
data[pos++] = p_byte;
}
Expand Down
4 changes: 2 additions & 2 deletions core/io/file_access_zip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ Error FileAccessZip::open_internal(const String &p_path, int p_mode_flags) {

ERR_FAIL_COND_V(p_mode_flags & FileAccess::WRITE, FAILED);
ZipArchive *arch = ZipArchive::get_singleton();
ERR_FAIL_COND_V(!arch, FAILED);
ERR_FAIL_NULL_V(arch, FAILED);
zfile = arch->get_file_handle(p_path);
ERR_FAIL_COND_V(!zfile, FAILED);

Expand All @@ -255,7 +255,7 @@ void FileAccessZip::_close() {
}

ZipArchive *arch = ZipArchive::get_singleton();
ERR_FAIL_COND(!arch);
ERR_FAIL_NULL(arch);
arch->close_handle(zfile);
zfile = nullptr;
}
Expand Down
16 changes: 8 additions & 8 deletions core/io/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2356,7 +2356,7 @@ void Image::initialize_data(const char **p_xpm) {
}

Color *colorptr = colormap.getptr(pixelstr);
ERR_FAIL_COND(!colorptr);
ERR_FAIL_NULL(colorptr);
uint8_t pixel[4];
for (uint32_t i = 0; i < pixel_size; i++) {
pixel[i] = CLAMP((*colorptr)[i] * 255, 0, 255);
Expand Down Expand Up @@ -2646,23 +2646,23 @@ Error Image::compress_from_channels(CompressMode p_mode, UsedChannels p_channels

switch (p_mode) {
case COMPRESS_S3TC: {
ERR_FAIL_COND_V(!_image_compress_bc_func, ERR_UNAVAILABLE);
ERR_FAIL_NULL_V(_image_compress_bc_func, ERR_UNAVAILABLE);
_image_compress_bc_func(this, p_channels);
} break;
case COMPRESS_ETC: {
ERR_FAIL_COND_V(!_image_compress_etc1_func, ERR_UNAVAILABLE);
ERR_FAIL_NULL_V(_image_compress_etc1_func, ERR_UNAVAILABLE);
_image_compress_etc1_func(this);
} break;
case COMPRESS_ETC2: {
ERR_FAIL_COND_V(!_image_compress_etc2_func, ERR_UNAVAILABLE);
ERR_FAIL_NULL_V(_image_compress_etc2_func, ERR_UNAVAILABLE);
_image_compress_etc2_func(this, p_channels);
} break;
case COMPRESS_BPTC: {
ERR_FAIL_COND_V(!_image_compress_bptc_func, ERR_UNAVAILABLE);
ERR_FAIL_NULL_V(_image_compress_bptc_func, ERR_UNAVAILABLE);
_image_compress_bptc_func(this, p_channels);
} break;
case COMPRESS_ASTC: {
ERR_FAIL_COND_V(!_image_compress_astc_func, ERR_UNAVAILABLE);
ERR_FAIL_NULL_V(_image_compress_astc_func, ERR_UNAVAILABLE);
_image_compress_astc_func(this, p_astc_format);
} break;
case COMPRESS_MAX: {
Expand Down Expand Up @@ -3655,7 +3655,7 @@ void Image::bump_map_to_normal_map(float bump_scale) {
const uint8_t *rp = data.ptr();
uint8_t *wp = result_image.ptrw();

ERR_FAIL_COND(!rp);
ERR_FAIL_NULL(rp);

unsigned char *write_ptr = wp;
float *read_ptr = (float *)rp;
Expand Down Expand Up @@ -3916,7 +3916,7 @@ Error Image::_load_from_buffer(const Vector<uint8_t> &p_array, ImageMemLoadFunc
int buffer_size = p_array.size();

ERR_FAIL_COND_V(buffer_size == 0, ERR_INVALID_PARAMETER);
ERR_FAIL_COND_V(!p_loader, ERR_INVALID_PARAMETER);
ERR_FAIL_NULL_V(p_loader, ERR_INVALID_PARAMETER);

const uint8_t *r = p_array.ptr();

Expand Down
2 changes: 1 addition & 1 deletion core/io/ip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ IP *(*IP::_create)() = nullptr;

IP *IP::create() {
ERR_FAIL_COND_V_MSG(singleton, nullptr, "IP singleton already exist.");
ERR_FAIL_COND_V(!_create, nullptr);
ERR_FAIL_NULL_V(_create, nullptr);
return _create();
}

Expand Down
4 changes: 2 additions & 2 deletions core/io/marshalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
} else {
Object *obj = ClassDB::instantiate(str);

ERR_FAIL_COND_V(!obj, ERR_UNAVAILABLE);
ERR_FAIL_NULL_V(obj, ERR_UNAVAILABLE);
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);

int32_t count = decode_uint32(buf);
Expand Down Expand Up @@ -1576,7 +1576,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
buf += len;
}
Variant *v = d.getptr(E);
ERR_FAIL_COND_V(!v, ERR_BUG);
ERR_FAIL_NULL_V(v, ERR_BUG);
err = encode_variant(*v, buf, len, p_full_objects, p_depth + 1);
ERR_FAIL_COND_V(err, err);
ERR_FAIL_COND_V(len % 4, ERR_BUG);
Expand Down
6 changes: 3 additions & 3 deletions core/io/packed_data_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ Variant PackedDataContainer::_get_at_ofs(uint32_t p_ofs, const uint8_t *p_buf, b
uint32_t PackedDataContainer::_type_at_ofs(uint32_t p_ofs) const {
ERR_FAIL_COND_V(p_ofs + 4 > (uint32_t)data.size(), 0);
const uint8_t *rd = data.ptr();
ERR_FAIL_COND_V(!rd, 0);
ERR_FAIL_NULL_V(rd, 0);
const uint8_t *r = &rd[p_ofs];
uint32_t type = decode_uint32(r);

Expand All @@ -135,7 +135,7 @@ uint32_t PackedDataContainer::_type_at_ofs(uint32_t p_ofs) const {
int PackedDataContainer::_size(uint32_t p_ofs) const {
ERR_FAIL_COND_V(p_ofs + 4 > (uint32_t)data.size(), 0);
const uint8_t *rd = data.ptr();
ERR_FAIL_COND_V(!rd, 0);
ERR_FAIL_NULL_V(rd, 0);
const uint8_t *r = &rd[p_ofs];
uint32_t type = decode_uint32(r);

Expand All @@ -156,7 +156,7 @@ Variant PackedDataContainer::_key_at_ofs(uint32_t p_ofs, const Variant &p_key, b
const uint8_t *rd = data.ptr();
if (!rd) {
err = true;
ERR_FAIL_COND_V(!rd, Variant());
ERR_FAIL_NULL_V(rd, Variant());
}
const uint8_t *r = &rd[p_ofs];
uint32_t type = decode_uint32(r);
Expand Down
2 changes: 1 addition & 1 deletion core/io/resource_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,7 @@ bool ResourceLoader::add_custom_resource_format_loader(String script_path) {

Object *obj = ClassDB::instantiate(ibt);

ERR_FAIL_COND_V_MSG(obj == nullptr, false, "Cannot instance script as custom resource loader, expected 'ResourceFormatLoader' inheritance, got: " + String(ibt) + ".");
ERR_FAIL_NULL_V_MSG(obj, false, "Cannot instance script as custom resource loader, expected 'ResourceFormatLoader' inheritance, got: " + String(ibt) + ".");

Ref<ResourceFormatLoader> crl = Object::cast_to<ResourceFormatLoader>(obj);
crl->set_script(s);
Expand Down
2 changes: 1 addition & 1 deletion core/io/resource_saver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ bool ResourceSaver::add_custom_resource_format_saver(String script_path) {

Object *obj = ClassDB::instantiate(ibt);

ERR_FAIL_COND_V_MSG(obj == nullptr, false, "Cannot instance script as custom resource saver, expected 'ResourceFormatSaver' inheritance, got: " + String(ibt) + ".");
ERR_FAIL_NULL_V_MSG(obj, false, "Cannot instance script as custom resource saver, expected 'ResourceFormatSaver' inheritance, got: " + String(ibt) + ".");

Ref<ResourceFormatSaver> crl = Object::cast_to<ResourceFormatSaver>(obj);
crl->set_script(s);
Expand Down
4 changes: 2 additions & 2 deletions core/io/stream_peer_gzip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Error StreamPeerGZIP::_start(bool p_compress, bool p_is_deflate, int buffer_size
}

Error StreamPeerGZIP::_process(uint8_t *p_dst, int p_dst_size, const uint8_t *p_src, int p_src_size, int &r_consumed, int &r_out, bool p_close) {
ERR_FAIL_COND_V(!ctx, ERR_UNCONFIGURED);
ERR_FAIL_NULL_V(ctx, ERR_UNCONFIGURED);
z_stream &strm = *(z_stream *)ctx;
strm.avail_in = p_src_size;
strm.avail_out = p_dst_size;
Expand Down Expand Up @@ -132,7 +132,7 @@ Error StreamPeerGZIP::put_data(const uint8_t *p_data, int p_bytes) {
}

Error StreamPeerGZIP::put_partial_data(const uint8_t *p_data, int p_bytes, int &r_sent) {
ERR_FAIL_COND_V(!ctx, ERR_UNCONFIGURED);
ERR_FAIL_NULL_V(ctx, ERR_UNCONFIGURED);
ERR_FAIL_COND_V(p_bytes < 0, ERR_INVALID_PARAMETER);

// Ensure we have enough space in temporary buffer.
Expand Down
4 changes: 2 additions & 2 deletions core/io/xml_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ uint64_t XMLParser::get_node_offset() const {
}

Error XMLParser::seek(uint64_t p_pos) {
ERR_FAIL_COND_V(!data, ERR_FILE_EOF);
ERR_FAIL_NULL_V(data, ERR_FILE_EOF);
ERR_FAIL_COND_V(p_pos >= length, ERR_FILE_EOF);

P = data + p_pos;
Expand Down Expand Up @@ -474,7 +474,7 @@ Error XMLParser::open_buffer(const Vector<uint8_t> &p_buffer) {

Error XMLParser::_open_buffer(const uint8_t *p_buffer, size_t p_size) {
ERR_FAIL_COND_V(p_size == 0, ERR_INVALID_DATA);
ERR_FAIL_COND_V(!p_buffer, ERR_INVALID_DATA);
ERR_FAIL_NULL_V(p_buffer, ERR_INVALID_DATA);

if (data_copy) {
memdelete_arr(data_copy);
Expand Down
Loading