diff options
Diffstat (limited to 'core/io')
36 files changed, 690 insertions, 364 deletions
diff --git a/core/io/compression.cpp b/core/io/compression.cpp index 1b6786d888..99ca8107e4 100644 --- a/core/io/compression.cpp +++ b/core/io/compression.cpp @@ -62,8 +62,9 @@ int Compression::compress(uint8_t *p_dst, const uint8_t *p_src, int p_src_size, strm.opaque = Z_NULL; int level = p_mode == MODE_DEFLATE ? zlib_level : gzip_level; int err = deflateInit2(&strm, level, Z_DEFLATED, window_bits, 8, Z_DEFAULT_STRATEGY); - if (err != Z_OK) + if (err != Z_OK) { return -1; + } strm.avail_in = p_src_size; int aout = deflateBound(&strm, p_src_size); @@ -97,8 +98,9 @@ int Compression::get_max_compressed_buffer_size(int p_src_size, Mode p_mode) { switch (p_mode) { case MODE_FASTLZ: { int ss = p_src_size + p_src_size * 6 / 100; - if (ss < 66) + if (ss < 66) { ss = 66; + } return ss; } break; @@ -111,8 +113,9 @@ int Compression::get_max_compressed_buffer_size(int p_src_size, Mode p_mode) { strm.zfree = zipio_free; strm.opaque = Z_NULL; int err = deflateInit2(&strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED, window_bits, 8, Z_DEFAULT_STRATEGY); - if (err != Z_OK) + if (err != Z_OK) { return -1; + } int aout = deflateBound(&strm, p_src_size); deflateEnd(&strm); return aout; diff --git a/core/io/config_file.cpp b/core/io/config_file.cpp index 334c8f143e..1af9142317 100644 --- a/core/io/config_file.cpp +++ b/core/io/config_file.cpp @@ -63,8 +63,9 @@ PackedStringArray ConfigFile::_get_section_keys(const String &p_section) const { void ConfigFile::set_value(const String &p_section, const String &p_key, const Variant &p_value) { if (p_value.get_type() == Variant::NIL) { //erase - if (!values.has(p_section)) + if (!values.has(p_section)) { return; // ? + } values[p_section].erase(p_key); if (values[p_section].empty()) { values.erase(p_section); @@ -94,8 +95,9 @@ bool ConfigFile::has_section(const String &p_section) const { } bool ConfigFile::has_section_key(const String &p_section, const String &p_key) const { - if (!values.has(p_section)) + if (!values.has(p_section)) { return false; + } return values[p_section].has(p_key); } @@ -130,8 +132,9 @@ Error ConfigFile::save(const String &p_path) { FileAccess *file = FileAccess::open(p_path, FileAccess::WRITE, &err); if (err) { - if (file) + if (file) { memdelete(file); + } return err; } @@ -142,8 +145,9 @@ Error ConfigFile::save_encrypted(const String &p_path, const Vector<uint8_t> &p_ Error err; FileAccess *f = FileAccess::open(p_path, FileAccess::WRITE, &err); - if (err) + if (err) { return err; + } FileAccessEncrypted *fae = memnew(FileAccessEncrypted); err = fae->open_and_parse(f, p_key, FileAccessEncrypted::MODE_WRITE_AES256); @@ -159,8 +163,9 @@ Error ConfigFile::save_encrypted_pass(const String &p_path, const String &p_pass Error err; FileAccess *f = FileAccess::open(p_path, FileAccess::WRITE, &err); - if (err) + if (err) { return err; + } FileAccessEncrypted *fae = memnew(FileAccessEncrypted); err = fae->open_and_parse_password(f, p_pass, FileAccessEncrypted::MODE_WRITE_AES256); @@ -175,8 +180,9 @@ Error ConfigFile::save_encrypted_pass(const String &p_path, const String &p_pass Error ConfigFile::_internal_save(FileAccess *file) { for (OrderedHashMap<String, OrderedHashMap<String, Variant>>::Element E = values.front(); E; E = E.next()) { - if (E != values.front()) + if (E != values.front()) { file->store_string("\n"); + } file->store_string("[" + E.key() + "]\n\n"); for (OrderedHashMap<String, Variant>::Element F = E.get().front(); F; F = F.next()) { @@ -195,8 +201,9 @@ Error ConfigFile::load(const String &p_path) { Error err; FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err); - if (!f) + if (!f) { return err; + } return _internal_load(p_path, f); } @@ -205,8 +212,9 @@ Error ConfigFile::load_encrypted(const String &p_path, const Vector<uint8_t> &p_ Error err; FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err); - if (err) + if (err) { return err; + } FileAccessEncrypted *fae = memnew(FileAccessEncrypted); err = fae->open_and_parse(f, p_key, FileAccessEncrypted::MODE_READ); @@ -222,8 +230,9 @@ Error ConfigFile::load_encrypted_pass(const String &p_path, const String &p_pass Error err; FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err); - if (err) + if (err) { return err; + } FileAccessEncrypted *fae = memnew(FileAccessEncrypted); err = fae->open_and_parse_password(f, p_pass, FileAccessEncrypted::MODE_READ); diff --git a/core/io/file_access_compressed.cpp b/core/io/file_access_compressed.cpp index 422100010c..7817ccb773 100644 --- a/core/io/file_access_compressed.cpp +++ b/core/io/file_access_compressed.cpp @@ -34,11 +34,12 @@ void FileAccessCompressed::configure(const String &p_magic, Compression::Mode p_mode, int p_block_size) { magic = p_magic.ascii().get_data(); - if (magic.length() > 4) + if (magic.length() > 4) { magic = magic.substr(0, 4); - else { - while (magic.length() < 4) + } else { + while (magic.length() < 4) { magic += " "; + } } cmode = p_mode; @@ -97,8 +98,9 @@ Error FileAccessCompressed::open_after_magic(FileAccess *p_base) { Error FileAccessCompressed::_open(const String &p_path, int p_mode_flags) { ERR_FAIL_COND_V(p_mode_flags == READ_WRITE, ERR_UNAVAILABLE); - if (f) + if (f) { close(); + } Error err; f = FileAccess::open(p_path, p_mode_flags, &err); @@ -134,8 +136,9 @@ Error FileAccessCompressed::_open(const String &p_path, int p_mode_flags) { } void FileAccessCompressed::close() { - if (!f) + if (!f) { return; + } if (writing) { //save block table and all compressed blocks @@ -165,8 +168,9 @@ void FileAccessCompressed::close() { } f->seek(16); //ok write block sizes - for (int i = 0; i < bc; i++) + for (int i = 0; i < bc; i++) { f->store_32(block_sizes[i]); + } f->seek_end(); f->store_buffer((const uint8_t *)mgc.get_data(), mgc.length()); //magic at the end too @@ -306,8 +310,9 @@ int FileAccessCompressed::get_buffer(uint8_t *p_dst, int p_length) const { } else { read_block--; at_end = true; - if (i < p_length - 1) + if (i < p_length - 1) { read_eof = true; + } return i; } } @@ -337,22 +342,25 @@ void FileAccessCompressed::store_8(uint8_t p_dest) { bool FileAccessCompressed::file_exists(const String &p_name) { FileAccess *fa = FileAccess::open(p_name, FileAccess::READ); - if (!fa) + if (!fa) { return false; + } memdelete(fa); return true; } uint64_t FileAccessCompressed::_get_modified_time(const String &p_file) { - if (f) + if (f) { return f->get_modified_time(p_file); - else + } else { return 0; + } } uint32_t FileAccessCompressed::_get_unix_permissions(const String &p_file) { - if (f) + if (f) { return f->_get_unix_permissions(p_file); + } return 0; } @@ -364,6 +372,7 @@ Error FileAccessCompressed::_set_unix_permissions(const String &p_file, uint32_t } FileAccessCompressed::~FileAccessCompressed() { - if (f) + if (f) { close(); + } } diff --git a/core/io/file_access_encrypted.cpp b/core/io/file_access_encrypted.cpp index ceda6c5eb2..5938914cb0 100644 --- a/core/io/file_access_encrypted.cpp +++ b/core/io/file_access_encrypted.cpp @@ -115,8 +115,9 @@ Error FileAccessEncrypted::_open(const String &p_path, int p_mode_flags) { } void FileAccessEncrypted::close() { - if (!file) + if (!file) { return; + } if (writing) { Vector<uint8_t> compressed; @@ -166,22 +167,25 @@ bool FileAccessEncrypted::is_open() const { } String FileAccessEncrypted::get_path() const { - if (file) + if (file) { return file->get_path(); - else + } else { return ""; + } } String FileAccessEncrypted::get_path_absolute() const { - if (file) + if (file) { return file->get_path_absolute(); - else + } else { return ""; + } } void FileAccessEncrypted::seek(size_t p_position) { - if (p_position > (size_t)data.size()) + if (p_position > (size_t)data.size()) { p_position = data.size(); + } pos = p_position; eofed = false; @@ -270,8 +274,9 @@ void FileAccessEncrypted::store_8(uint8_t p_dest) { bool FileAccessEncrypted::file_exists(const String &p_name) { FileAccess *fa = FileAccess::open(p_name, FileAccess::READ); - if (!fa) + if (!fa) { return false; + } memdelete(fa); return true; } @@ -290,6 +295,7 @@ Error FileAccessEncrypted::_set_unix_permissions(const String &p_file, uint32_t } FileAccessEncrypted::~FileAccessEncrypted() { - if (file) + if (file) { close(); + } } diff --git a/core/io/file_access_memory.cpp b/core/io/file_access_memory.cpp index 790f946752..3c5f846941 100644 --- a/core/io/file_access_memory.cpp +++ b/core/io/file_access_memory.cpp @@ -43,18 +43,20 @@ void FileAccessMemory::register_file(String p_name, Vector<uint8_t> p_data) { } String name; - if (ProjectSettings::get_singleton()) + if (ProjectSettings::get_singleton()) { name = ProjectSettings::get_singleton()->globalize_path(p_name); - else + } else { name = p_name; + } //name = DirAccess::normalize_path(name); (*files)[name] = p_data; } void FileAccessMemory::cleanup() { - if (!files) + if (!files) { return; + } memdelete(files); } diff --git a/core/io/file_access_network.cpp b/core/io/file_access_network.cpp index 4b7f99e5b0..6890740d90 100644 --- a/core/io/file_access_network.cpp +++ b/core/io/file_access_network.cpp @@ -115,8 +115,9 @@ void FileAccessNetworkClient::_thread_func() { } } - if (accesses.has(id)) + if (accesses.has(id)) { fa = accesses[id]; + } switch (response) { case FileAccessNetwork::RESPONSE_OPEN: { @@ -140,8 +141,9 @@ void FileAccessNetworkClient::_thread_func() { block.resize(len); client->get_data(block.ptrw(), len); - if (fa) //may have been queued + if (fa) { //may have been queued fa->_set_block(offset, block); + } } break; case FileAccessNetwork::RESPONSE_FILE_EXISTS: { @@ -244,8 +246,9 @@ void FileAccessNetwork::_set_block(int p_offset, const Vector<uint8_t> &p_block) void FileAccessNetwork::_respond(size_t p_len, Error p_status) { DEBUG_PRINT("GOT RESPONSE - len: " + itos(p_len) + " status: " + itos(p_status)); response = p_status; - if (response != OK) + if (response != OK) { return; + } opened = true; total_size = p_len; int pc = ((total_size - 1) / page_size) + 1; @@ -254,8 +257,9 @@ void FileAccessNetwork::_respond(size_t p_len, Error p_status) { Error FileAccessNetwork::_open(const String &p_path, int p_mode_flags) { ERR_FAIL_COND_V(p_mode_flags != READ, ERR_UNAVAILABLE); - if (opened) + if (opened) { close(); + } FileAccessNetworkClient *nc = FileAccessNetworkClient::singleton; DEBUG_PRINT("open: " + p_path); @@ -287,8 +291,9 @@ Error FileAccessNetwork::_open(const String &p_path, int p_mode_flags) { } void FileAccessNetwork::close() { - if (!opened) + if (!opened) { return; + } FileAccessNetworkClient *nc = FileAccessNetworkClient::singleton; @@ -342,8 +347,9 @@ uint8_t FileAccessNetwork::get_8() const { } void FileAccessNetwork::_queue_page(int p_page) const { - if (p_page >= pages.size()) + if (p_page >= pages.size()) { return; + } if (pages[p_page].buffer.empty() && !pages[p_page].queued) { FileAccessNetworkClient *nc = FileAccessNetworkClient::singleton; { diff --git a/core/io/file_access_pack.cpp b/core/io/file_access_pack.cpp index bb65a1afbc..00c4e76efe 100644 --- a/core/io/file_access_pack.cpp +++ b/core/io/file_access_pack.cpp @@ -54,12 +54,14 @@ void PackedData::add_path(const String &pkg_path, const String &path, uint64_t o pf.pack = pkg_path; pf.offset = ofs; pf.size = size; - for (int i = 0; i < 16; i++) + for (int i = 0; i < 16; i++) { pf.md5[i] = p_md5[i]; + } pf.src = p_src; - if (!exists || p_replace_files) + if (!exists || p_replace_files) { files[pmd5] = pf; + } if (!exists) { //search for dir @@ -106,8 +108,9 @@ PackedData::PackedData() { } void PackedData::_free_packed_dirs(PackedDir *p_dir) { - for (Map<String, PackedDir *>::Element *E = p_dir->subdirs.front(); E; E = E->next()) + for (Map<String, PackedDir *>::Element *E = p_dir->subdirs.front(); E; E = E->next()) { _free_packed_dirs(E->get()); + } memdelete(p_dir); } @@ -122,8 +125,9 @@ PackedData::~PackedData() { bool PackedSourcePCK::try_open_pack(const String &p_path, bool p_replace_files) { FileAccess *f = FileAccess::open(p_path, FileAccess::READ); - if (!f) + if (!f) { return false; + } uint32_t magic = f->get_32(); @@ -252,8 +256,9 @@ uint8_t FileAccessPack::get_8() const { } int FileAccessPack::get_buffer(uint8_t *p_dst, int p_length) const { - if (eof) + if (eof) { return 0; + } uint64_t to_read = p_length; if (to_read + pos > pf.size) { @@ -263,8 +268,9 @@ int FileAccessPack::get_buffer(uint8_t *p_dst, int p_length) const { pos += p_length; - if (to_read <= 0) + if (to_read <= 0) { return 0; + } f->get_buffer(p_dst, to_read); return to_read; @@ -276,8 +282,9 @@ void FileAccessPack::set_endian_swap(bool p_swap) { } Error FileAccessPack::get_error() const { - if (eof) + if (eof) { return ERR_FILE_EOF; + } return OK; } @@ -308,8 +315,9 @@ FileAccessPack::FileAccessPack(const String &p_path, const PackedData::PackedFil } FileAccessPack::~FileAccessPack() { - if (f) + if (f) { memdelete(f); + } } ////////////////////////////////////////////////////////////////////////////////// @@ -378,8 +386,9 @@ Error DirAccessPack::change_dir(String p_dir) { nd = nd.simplify_path(); - if (nd == "") + if (nd == "") { nd = "."; + } if (nd.begins_with("/")) { nd = nd.replace_first("/", ""); @@ -390,10 +399,11 @@ Error DirAccessPack::change_dir(String p_dir) { PackedData::PackedDir *pd; - if (absolute) + if (absolute) { pd = PackedData::get_singleton()->root; - else + } else { pd = current; + } for (int i = 0; i < paths.size(); i++) { String p = paths[i]; diff --git a/core/io/file_access_pack.h b/core/io/file_access_pack.h index a5d4c1f1b6..320a6cb216 100644 --- a/core/io/file_access_pack.h +++ b/core/io/file_access_pack.h @@ -175,10 +175,12 @@ public: FileAccess *PackedData::try_open_path(const String &p_path) { PathMD5 pmd5(p_path.md5_buffer()); Map<PathMD5, PackedFile>::Element *E = files.find(pmd5); - if (!E) + if (!E) { return nullptr; //not found - if (E->get().offset == 0) + } + if (E->get().offset == 0) { return nullptr; //was erased + } return E->get().src->get_file(p_path, &E->get()); } diff --git a/core/io/file_access_zip.cpp b/core/io/file_access_zip.cpp index 5dde5aa6ce..c3a62706c7 100644 --- a/core/io/file_access_zip.cpp +++ b/core/io/file_access_zip.cpp @@ -149,14 +149,16 @@ unzFile ZipArchive::get_file_handle(String p_file) const { bool ZipArchive::try_open_pack(const String &p_path, bool p_replace_files) { //printf("opening zip pack %ls, %i, %i\n", p_name.c_str(), p_name.extension().nocasecmp_to("zip"), p_name.extension().nocasecmp_to("pcz")); - if (p_path.get_extension().nocasecmp_to("zip") != 0 && p_path.get_extension().nocasecmp_to("pcz") != 0) + if (p_path.get_extension().nocasecmp_to("zip") != 0 && p_path.get_extension().nocasecmp_to("pcz") != 0) { return false; + } zlib_filefunc_def io; FileAccess *fa = FileAccess::open(p_path, FileAccess::READ); - if (!fa) + if (!fa) { return false; + } io.opaque = fa; io.zopen_file = godot_open; io.zread_file = godot_read; @@ -252,8 +254,9 @@ Error FileAccessZip::_open(const String &p_path, int p_mode_flags) { } void FileAccessZip::close() { - if (!zfile) + if (!zfile) { return; + } ZipArchive *arch = ZipArchive::get_singleton(); ERR_FAIL_COND(!arch); @@ -300,12 +303,14 @@ uint8_t FileAccessZip::get_8() const { int FileAccessZip::get_buffer(uint8_t *p_dst, int p_length) const { ERR_FAIL_COND_V(!zfile, -1); at_eof = unzeof(zfile); - if (at_eof) + if (at_eof) { return 0; + } int read = unzReadCurrentFile(zfile, p_dst, p_length); ERR_FAIL_COND_V(read < 0, read); - if (read < p_length) + if (read < p_length) { at_eof = true; + } return read; } diff --git a/core/io/http_client.cpp b/core/io/http_client.cpp index 2a1a435b8e..40debae9e5 100644 --- a/core/io/http_client.cpp +++ b/core/io/http_client.cpp @@ -240,8 +240,9 @@ int HTTPClient::get_response_code() const { } Error HTTPClient::get_response_headers(List<String> *r_response) { - if (!response_headers.size()) + if (!response_headers.size()) { return ERR_INVALID_PARAMETER; + } for (int i = 0; i < response_headers.size(); i++) { r_response->push_back(response_headers[i]); @@ -253,8 +254,9 @@ Error HTTPClient::get_response_headers(List<String> *r_response) { } void HTTPClient::close() { - if (tcp_connection->get_status() != StreamPeerTCP::STATUS_NONE) + if (tcp_connection->get_status() != StreamPeerTCP::STATUS_NONE) { tcp_connection->disconnect_from_host(); + } connection.unref(); status = STATUS_DISCONNECTED; @@ -393,8 +395,9 @@ Error HTTPClient::poll() { return ERR_CONNECTION_ERROR; } - if (rec == 0) + if (rec == 0) { return OK; // Still requesting, keep trying! + } response_str.push_back(byte); int rs = response_str.size(); @@ -424,8 +427,9 @@ Error HTTPClient::poll() { for (int i = 0; i < responses.size(); i++) { String header = responses[i].strip_edges(); String s = header.to_lower(); - if (s.length() == 0) + if (s.length() == 0) { continue; + } if (s.begins_with("content-length:")) { body_size = s.substr(s.find(":") + 1, s.length()).strip_edges().to_int(); body_left = body_size; @@ -501,8 +505,9 @@ PackedByteArray HTTPClient::read_response_body_chunk() { int rec = 0; err = _get_http_data(&b, 1, rec); - if (rec == 0) + if (rec == 0) { break; + } chunk.push_back(b); int cs = chunk.size(); @@ -524,8 +529,9 @@ PackedByteArray HTTPClient::read_response_body_chunk() { int rec = 0; err = _get_http_data(&b, 1, rec); - if (rec == 0) + if (rec == 0) { break; + } chunk.push_back(b); @@ -540,13 +546,13 @@ PackedByteArray HTTPClient::read_response_body_chunk() { for (int i = 0; i < chunk.size() - 2; i++) { char c = chunk[i]; int v = 0; - if (c >= '0' && c <= '9') + if (c >= '0' && c <= '9') { v = c - '0'; - else if (c >= 'a' && c <= 'f') + } else if (c >= 'a' && c <= 'f') { v = c - 'a' + 10; - else if (c >= 'A' && c <= 'F') + } else if (c >= 'A' && c <= 'F') { v = c - 'A' + 10; - else { + } else { ERR_PRINT("HTTP Chunk len not in hex!!"); status = STATUS_CONNECTION_ERROR; break; @@ -615,8 +621,9 @@ PackedByteArray HTTPClient::read_response_body_chunk() { body_left -= rec; } } - if (err != OK) + if (err != OK) { break; + } } } @@ -727,8 +734,9 @@ Dictionary HTTPClient::_get_response_headers_as_dictionary() { for (const List<String>::Element *E = rh.front(); E; E = E->next()) { const String &s = E->get(); int sp = s.find(":"); - if (sp == -1) + if (sp == -1) { continue; + } String key = s.substr(0, sp).strip_edges(); String value = s.substr(sp + 1, s.length()).strip_edges(); ret[key] = value; diff --git a/core/io/image_loader.cpp b/core/io/image_loader.cpp index 06e3cc029d..b1e92eb87f 100644 --- a/core/io/image_loader.cpp +++ b/core/io/image_loader.cpp @@ -36,8 +36,9 @@ bool ImageFormatLoader::recognize(const String &p_extension) const { List<String> extensions; get_recognized_extensions(&extensions); for (List<String>::Element *E = extensions.front(); E; E = E->next()) { - if (E->get().nocasecmp_to(p_extension) == 0) + if (E->get().nocasecmp_to(p_extension) == 0) { return true; + } } return false; @@ -59,23 +60,26 @@ Error ImageLoader::load_image(String p_file, Ref<Image> p_image, FileAccess *p_c String extension = p_file.get_extension(); for (int i = 0; i < loader.size(); i++) { - if (!loader[i]->recognize(extension)) + if (!loader[i]->recognize(extension)) { continue; + } Error err = loader[i]->load_image(p_image, f, p_force_linear, p_scale); if (err != OK) { ERR_PRINT("Error loading image: " + p_file); } if (err != ERR_FILE_UNRECOGNIZED) { - if (!p_custom) + if (!p_custom) { memdelete(f); + } return err; } } - if (!p_custom) + if (!p_custom) { memdelete(f); + } return ERR_FILE_UNRECOGNIZED; } @@ -88,8 +92,9 @@ void ImageLoader::get_recognized_extensions(List<String> *p_extensions) { ImageFormatLoader *ImageLoader::recognize(const String &p_extension) { for (int i = 0; i < loader.size(); i++) { - if (loader[i]->recognize(p_extension)) + if (loader[i]->recognize(p_extension)) { return loader[i]; + } } return nullptr; diff --git a/core/io/ip.cpp b/core/io/ip.cpp index 642602d0bc..653959b393 100644 --- a/core/io/ip.cpp +++ b/core/io/ip.cpp @@ -61,8 +61,9 @@ struct _IP_ResolverPrivate { IP::ResolverID find_empty_id() const { for (int i = 0; i < IP::RESOLVER_MAX_QUERIES; i++) { - if (queue[i].status == IP::RESOLVER_STATUS_NONE) + if (queue[i].status == IP::RESOLVER_STATUS_NONE) { return i; + } } return IP::RESOLVER_INVALID_ID; } @@ -76,14 +77,16 @@ struct _IP_ResolverPrivate { void resolve_queues() { for (int i = 0; i < IP::RESOLVER_MAX_QUERIES; i++) { - if (queue[i].status != IP::RESOLVER_STATUS_WAITING) + if (queue[i].status != IP::RESOLVER_STATUS_WAITING) { continue; + } queue[i].response = IP::get_singleton()->resolve_hostname(queue[i].hostname, queue[i].type); - if (!queue[i].response.is_valid()) + if (!queue[i].response.is_valid()) { queue[i].status = IP::RESOLVER_STATUS_ERROR; - else + } else { queue[i].status = IP::RESOLVER_STATUS_DONE; + } } } @@ -138,10 +141,11 @@ IP::ResolverID IP::resolve_hostname_queue_item(const String &p_hostname, IP::Typ } else { resolver->queue[id].response = IP_Address(); resolver->queue[id].status = IP::RESOLVER_STATUS_WAITING; - if (resolver->thread) + if (resolver->thread) { resolver->sem.post(); - else + } else { resolver->resolve_queues(); + } } return id; diff --git a/core/io/ip_address.cpp b/core/io/ip_address.cpp index 817c2f060a..89b317bf93 100644 --- a/core/io/ip_address.cpp +++ b/core/io/ip_address.cpp @@ -39,19 +39,23 @@ IP_Address::operator Variant() const { #include <string.h> IP_Address::operator String() const { - if (wildcard) + if (wildcard) { return "*"; + } - if (!valid) + if (!valid) { return ""; + } - if (is_ipv4()) + if (is_ipv4()) { // IPv4 address mapped to IPv6 return itos(field8[12]) + "." + itos(field8[13]) + "." + itos(field8[14]) + "." + itos(field8[15]); + } String ret; for (int i = 0; i < 8; i++) { - if (i > 0) + if (i > 0) { ret = ret + ":"; + } uint16_t num = (field8[i * 2] << 8) + field8[i * 2 + 1]; ret = ret + String::num_int64(num, 16); }; @@ -187,8 +191,9 @@ const uint8_t *IP_Address::get_ipv6() const { void IP_Address::set_ipv6(const uint8_t *p_buf) { clear(); valid = true; - for (int i = 0; i < 16; i++) + for (int i = 0; i < 16; i++) { field8[i] = p_buf[i]; + } } IP_Address::IP_Address(const String &p_string) { diff --git a/core/io/ip_address.h b/core/io/ip_address.h index 39948ce211..2f8f83503e 100644 --- a/core/io/ip_address.h +++ b/core/io/ip_address.h @@ -51,23 +51,32 @@ protected: public: //operator Variant() const; bool operator==(const IP_Address &p_ip) const { - if (p_ip.valid != valid) + if (p_ip.valid != valid) { return false; - if (!valid) + } + if (!valid) { return false; - for (int i = 0; i < 4; i++) - if (field32[i] != p_ip.field32[i]) + } + for (int i = 0; i < 4; i++) { + if (field32[i] != p_ip.field32[i]) { return false; + } + } return true; } + bool operator!=(const IP_Address &p_ip) const { - if (p_ip.valid != valid) + if (p_ip.valid != valid) { return true; - if (!valid) + } + if (!valid) { return true; - for (int i = 0; i < 4; i++) - if (field32[i] != p_ip.field32[i]) + } + for (int i = 0; i < 4; i++) { + if (field32[i] != p_ip.field32[i]) { return true; + } + } return false; } diff --git a/core/io/json.cpp b/core/io/json.cpp index baa62a4b0a..03f4e65220 100644 --- a/core/io/json.cpp +++ b/core/io/json.cpp @@ -48,8 +48,9 @@ const char *JSON::tk_name[TK_MAX] = { static String _make_indent(const String &p_indent, int p_size) { String indent_text = ""; if (!p_indent.empty()) { - for (int i = 0; i < p_size; i++) + for (int i = 0; i < p_size; i++) { indent_text += p_indent; + } } return indent_text; } @@ -98,8 +99,9 @@ String JSON::_print_var(const Variant &p_var, const String &p_indent, int p_cur_ List<Variant> keys; d.get_key_list(&keys); - if (p_sort_keys) + if (p_sort_keys) { keys.sort(); + } for (List<Variant>::Element *E = keys.front(); E; E = E->next()) { if (E != keys.front()) { @@ -241,8 +243,9 @@ Error JSON::_get_token(const CharType *p_str, int &index, int p_len, Token &r_to str += res; } else { - if (p_str[index] == '\n') + if (p_str[index] == '\n') { line++; + } str += p_str[index]; } index++; @@ -294,27 +297,29 @@ Error JSON::_parse_value(Variant &value, Token &token, const CharType *p_str, in if (token.type == TK_CURLY_BRACKET_OPEN) { Dictionary d; Error err = _parse_object(d, p_str, index, p_len, line, r_err_str); - if (err) + if (err) { return err; + } value = d; return OK; } else if (token.type == TK_BRACKET_OPEN) { Array a; Error err = _parse_array(a, p_str, index, p_len, line, r_err_str); - if (err) + if (err) { return err; + } value = a; return OK; } else if (token.type == TK_IDENTIFIER) { String id = token.value; - if (id == "true") + if (id == "true") { value = true; - else if (id == "false") + } else if (id == "false") { value = false; - else if (id == "null") + } else if (id == "null") { value = Variant(); - else { + } else { r_err_str = "Expected 'true','false' or 'null', got '" + id + "'."; return ERR_PARSE_ERROR; } @@ -338,8 +343,9 @@ Error JSON::_parse_array(Array &array, const CharType *p_str, int &index, int p_ while (index < p_len) { Error err = _get_token(p_str, index, p_len, token, line, r_err_str); - if (err != OK) + if (err != OK) { return err; + } if (token.type == TK_BRACKET_CLOSE) { return OK; @@ -357,8 +363,9 @@ Error JSON::_parse_array(Array &array, const CharType *p_str, int &index, int p_ Variant v; err = _parse_value(v, token, p_str, index, p_len, line, r_err_str); - if (err) + if (err) { return err; + } array.push_back(v); need_comma = true; @@ -376,8 +383,9 @@ Error JSON::_parse_object(Dictionary &object, const CharType *p_str, int &index, while (index < p_len) { if (at_key) { Error err = _get_token(p_str, index, p_len, token, line, r_err_str); - if (err != OK) + if (err != OK) { return err; + } if (token.type == TK_CURLY_BRACKET_CLOSE) { return OK; @@ -400,8 +408,9 @@ Error JSON::_parse_object(Dictionary &object, const CharType *p_str, int &index, key = token.value; err = _get_token(p_str, index, p_len, token, line, r_err_str); - if (err != OK) + if (err != OK) { return err; + } if (token.type != TK_COLON) { r_err_str = "Expected ':'"; return ERR_PARSE_ERROR; @@ -409,13 +418,15 @@ Error JSON::_parse_object(Dictionary &object, const CharType *p_str, int &index, at_key = false; } else { Error err = _get_token(p_str, index, p_len, token, line, r_err_str); - if (err != OK) + if (err != OK) { return err; + } Variant v; err = _parse_value(v, token, p_str, index, p_len, line, r_err_str); - if (err) + if (err) { return err; + } object[key] = v; need_comma = true; at_key = true; @@ -434,8 +445,9 @@ Error JSON::parse(const String &p_json, Variant &r_ret, String &r_err_str, int & String aux_key; Error err = _get_token(str, idx, len, token, r_err_line, r_err_str); - if (err) + if (err) { return err; + } err = _parse_value(r_ret, token, str, idx, len, r_err_line, r_err_str); diff --git a/core/io/logger.cpp b/core/io/logger.cpp index 23165b575e..ef78b1194e 100644 --- a/core/io/logger.cpp +++ b/core/io/logger.cpp @@ -67,10 +67,11 @@ void Logger::log_error(const char *p_function, const char *p_file, int p_line, c } const char *err_details; - if (p_rationale && *p_rationale) + if (p_rationale && *p_rationale) { err_details = p_rationale; - else + } else { err_details = p_code; + } logf_error("%s: %s\n", err_type, err_details); logf_error(" at: %s (%s:%i) - %s\n", p_function, p_file, p_line, p_code); diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp index fc0b037b07..eb39b1433f 100644 --- a/core/io/marshalls.cpp +++ b/core/io/marshalls.cpp @@ -107,8 +107,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int buf += 4; len -= 4; - if (r_len) + if (r_len) { *r_len = 4; + } switch (type & ENCODE_MASK) { case Variant::NIL: { @@ -118,23 +119,26 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); bool val = decode_uint32(buf); r_variant = val; - if (r_len) + if (r_len) { (*r_len) += 4; + } } break; case Variant::INT: { if (type & ENCODE_FLAG_64) { ERR_FAIL_COND_V(len < 8, ERR_INVALID_DATA); int64_t val = decode_uint64(buf); r_variant = val; - if (r_len) + if (r_len) { (*r_len) += 8; + } } else { ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); int32_t val = decode_uint32(buf); r_variant = val; - if (r_len) + if (r_len) { (*r_len) += 4; + } } } break; @@ -143,22 +147,25 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int ERR_FAIL_COND_V(len < 8, ERR_INVALID_DATA); double val = decode_double(buf); r_variant = val; - if (r_len) + if (r_len) { (*r_len) += 8; + } } else { ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); float val = decode_float(buf); r_variant = val; - if (r_len) + if (r_len) { (*r_len) += 4; + } } } break; case Variant::STRING: { String str; Error err = _decode_string(buf, len, r_len, str); - if (err) + if (err) { return err; + } r_variant = str; } break; @@ -171,8 +178,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int val.y = decode_float(&buf[4]); r_variant = val; - if (r_len) + if (r_len) { (*r_len) += 4 * 2; + } } break; case Variant::VECTOR2I: { @@ -182,8 +190,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int val.y = decode_uint32(&buf[4]); r_variant = val; - if (r_len) + if (r_len) { (*r_len) += 4 * 2; + } } break; case Variant::RECT2: { @@ -195,8 +204,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int val.size.y = decode_float(&buf[12]); r_variant = val; - if (r_len) + if (r_len) { (*r_len) += 4 * 4; + } } break; case Variant::RECT2I: { @@ -208,8 +218,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int val.size.y = decode_uint32(&buf[12]); r_variant = val; - if (r_len) + if (r_len) { (*r_len) += 4 * 4; + } } break; case Variant::VECTOR3: { @@ -220,8 +231,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int val.z = decode_float(&buf[8]); r_variant = val; - if (r_len) + if (r_len) { (*r_len) += 4 * 3; + } } break; case Variant::VECTOR3I: { @@ -232,8 +244,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int val.z = decode_uint32(&buf[8]); r_variant = val; - if (r_len) + if (r_len) { (*r_len) += 4 * 3; + } } break; case Variant::TRANSFORM2D: { @@ -247,8 +260,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int r_variant = val; - if (r_len) + if (r_len) { (*r_len) += 4 * 6; + } } break; case Variant::PLANE: { @@ -260,8 +274,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int val.d = decode_float(&buf[12]); r_variant = val; - if (r_len) + if (r_len) { (*r_len) += 4 * 4; + } } break; case Variant::QUAT: { @@ -273,8 +288,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int val.w = decode_float(&buf[12]); r_variant = val; - if (r_len) + if (r_len) { (*r_len) += 4 * 4; + } } break; case Variant::AABB: { @@ -288,8 +304,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int val.size.z = decode_float(&buf[20]); r_variant = val; - if (r_len) + if (r_len) { (*r_len) += 4 * 6; + } } break; case Variant::BASIS: { @@ -303,8 +320,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int r_variant = val; - if (r_len) + if (r_len) { (*r_len) += 4 * 9; + } } break; case Variant::TRANSFORM: { @@ -321,8 +339,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int r_variant = val; - if (r_len) + if (r_len) { (*r_len) += 4 * 12; + } } break; @@ -336,15 +355,17 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int val.a = decode_float(&buf[12]); r_variant = val; - if (r_len) + if (r_len) { (*r_len) += 4 * 4; + } } break; case Variant::STRING_NAME: { String str; Error err = _decode_string(buf, len, r_len, str); - if (err) + if (err) { return err; + } r_variant = StringName(str); } break; @@ -366,24 +387,28 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int len -= 12; buf += 12; - if (flags & 2) // Obsolete format with property separate from subpath + if (flags & 2) { // Obsolete format with property separate from subpath subnamecount++; + } uint32_t total = namecount + subnamecount; - if (r_len) + if (r_len) { (*r_len) += 12; + } for (uint32_t i = 0; i < total; i++) { String str; Error err = _decode_string(buf, len, r_len, str); - if (err) + if (err) { return err; + } - if (i < namecount) + if (i < namecount) { names.push_back(str); - else + } else { subnames.push_back(str); + } } r_variant = NodePath(names, subnames, flags & 1); @@ -403,8 +428,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int //this _is_ allowed ERR_FAIL_COND_V(len < 8, ERR_INVALID_DATA); ObjectID val = ObjectID(decode_uint64(buf)); - if (r_len) + if (r_len) { (*r_len) += 8; + } if (val.is_null()) { r_variant = (Object *)nullptr; @@ -421,8 +447,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int String str; Error err = _decode_string(buf, len, r_len, str); - if (err) + if (err) { return err; + } if (str == String()) { r_variant = (Object *)nullptr; @@ -442,14 +469,16 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int for (int i = 0; i < count; i++) { str = String(); err = _decode_string(buf, len, r_len, str); - if (err) + if (err) { return err; + } Variant value; int used; err = decode_variant(value, buf, len, &used, p_allow_objects); - if (err) + if (err) { return err; + } buf += used; len -= used; @@ -573,8 +602,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int r_variant = data; if (r_len) { - if (count % 4) + if (count % 4) { (*r_len) += 4 - count % 4; + } (*r_len) += 4 + count; } @@ -685,15 +715,17 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int buf += 4; len -= 4; - if (r_len) + if (r_len) { (*r_len) += 4; + } //printf("string count: %i\n",count); for (int32_t i = 0; i < count; i++) { String str; Error err = _decode_string(buf, len, r_len, str); - if (err) + if (err) { return err; + } strings.push_back(str); } @@ -726,8 +758,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int int adv = 4 * 2 * count; - if (r_len) + if (r_len) { (*r_len) += adv; + } } r_variant = varray; @@ -760,8 +793,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int int adv = 4 * 3 * count; - if (r_len) + if (r_len) { (*r_len) += adv; + } } r_variant = varray; @@ -795,8 +829,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int int adv = 4 * 4 * count; - if (r_len) + if (r_len) { (*r_len) += adv; + } } r_variant = carray; @@ -927,8 +962,9 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo encode_uint32(uint32_t(np.get_name_count()) | 0x80000000, buf); //for compatibility with the old format encode_uint32(np.get_subname_count(), buf + 4); uint32_t np_flags = 0; - if (np.is_absolute()) + if (np.is_absolute()) { np_flags |= 1; + } encode_uint32(np_flags, buf + 8); @@ -942,17 +978,19 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo for (int i = 0; i < total; i++) { String str; - if (i < np.get_name_count()) + if (i < np.get_name_count()) { str = np.get_name(i); - else + } else { str = np.get_subname(i - np.get_name_count()); + } CharString utf8 = str.utf8(); int pad = 0; - if (utf8.length() % 4) + if (utf8.length() % 4) { pad = 4 - utf8.length() % 4; + } if (buf) { encode_uint32(utf8.length(), buf); @@ -1157,8 +1195,9 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo int pc = 0; for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { - if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) + if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) { continue; + } pc++; } @@ -1170,19 +1209,22 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo r_len += 4; for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { - if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) + if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) { continue; + } _encode_string(E->get().name, buf, r_len); int len; Error err = encode_variant(obj->get(E->get().name), buf, len, p_full_objects); - if (err) + if (err) { return err; + } ERR_FAIL_COND_V(len % 4, ERR_BUG); r_len += len; - if (buf) + if (buf) { buf += len; + } } } } else { @@ -1230,15 +1272,17 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo encode_variant(E->get(), buf, len, p_full_objects); ERR_FAIL_COND_V(len % 4, ERR_BUG); r_len += len; - if (buf) + if (buf) { buf += len; + } Variant *v = d.getptr(E->get()); ERR_FAIL_COND_V(!v, ERR_BUG); encode_variant(*v, buf, len, p_full_objects); ERR_FAIL_COND_V(len % 4, ERR_BUG); r_len += len; - if (buf) + if (buf) { buf += len; + } } } break; @@ -1257,8 +1301,9 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo encode_variant(v.get(i), buf, len, p_full_objects); ERR_FAIL_COND_V(len % 4, ERR_BUG); r_len += len; - if (buf) + if (buf) { buf += len; + } } } break; @@ -1279,8 +1324,9 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo r_len += 4 + datalen * datasize; while (r_len % 4) { r_len++; - if (buf) + if (buf) { *(buf++) = 0; + } } } break; @@ -1293,8 +1339,9 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo encode_uint32(datalen, buf); buf += 4; const int32_t *r = data.ptr(); - for (int32_t i = 0; i < datalen; i++) + for (int32_t i = 0; i < datalen; i++) { encode_uint32(r[i], &buf[i * datasize]); + } } r_len += 4 + datalen * datasize; @@ -1309,8 +1356,9 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo encode_uint64(datalen, buf); buf += 4; const int64_t *r = data.ptr(); - for (int64_t i = 0; i < datalen; i++) + for (int64_t i = 0; i < datalen; i++) { encode_uint64(r[i], &buf[i * datasize]); + } } r_len += 4 + datalen * datasize; @@ -1325,8 +1373,9 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo encode_uint32(datalen, buf); buf += 4; const float *r = data.ptr(); - for (int i = 0; i < datalen; i++) + for (int i = 0; i < datalen; i++) { encode_float(r[i], &buf[i * datasize]); + } } r_len += 4 + datalen * datasize; @@ -1341,8 +1390,9 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo encode_uint32(datalen, buf); buf += 4; const double *r = data.ptr(); - for (int i = 0; i < datalen; i++) + for (int i = 0; i < datalen; i++) { encode_double(r[i], &buf[i * datasize]); + } } r_len += 4 + datalen * datasize; @@ -1372,8 +1422,9 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo r_len += 4 + utf8.length() + 1; while (r_len % 4) { r_len++; //pad - if (buf) + if (buf) { *(buf++) = 0; + } } } diff --git a/core/io/marshalls.h b/core/io/marshalls.h index 279f782b1a..c21a97ac8a 100644 --- a/core/io/marshalls.h +++ b/core/io/marshalls.h @@ -108,8 +108,9 @@ static inline int encode_cstring(const char *p_string, uint8_t *p_data) { len++; }; - if (p_data) + if (p_data) { *p_data = 0; + } return len + 1; } diff --git a/core/io/multiplayer_api.cpp b/core/io/multiplayer_api.cpp index a2f65660f2..2f17d9e746 100644 --- a/core/io/multiplayer_api.cpp +++ b/core/io/multiplayer_api.cpp @@ -53,8 +53,9 @@ _FORCE_INLINE_ bool _should_call_local(MultiplayerAPI::RPCMode mode, bool is_mas // Do nothing also. Remote cannot produce a local call. } break; case MultiplayerAPI::RPC_MODE_MASTERSYNC: { - if (is_master) + if (is_master) { r_skip_rpc = true; // I am the master, so skip remote call. + } [[fallthrough]]; } case MultiplayerAPI::RPC_MODE_REMOTESYNC: @@ -63,8 +64,9 @@ _FORCE_INLINE_ bool _should_call_local(MultiplayerAPI::RPCMode mode, bool is_mas return true; } break; case MultiplayerAPI::RPC_MODE_MASTER: { - if (is_master) + if (is_master) { r_skip_rpc = true; // I am the master, so skip remote call. + } return is_master; } break; case MultiplayerAPI::RPC_MODE_PUPPET: { @@ -97,13 +99,15 @@ _FORCE_INLINE_ bool _can_call_mode(Node *p_node, MultiplayerAPI::RPCMode mode, i } void MultiplayerAPI::poll() { - if (!network_peer.is_valid() || network_peer->get_connection_status() == NetworkedMultiplayerPeer::CONNECTION_DISCONNECTED) + if (!network_peer.is_valid() || network_peer->get_connection_status() == NetworkedMultiplayerPeer::CONNECTION_DISCONNECTED) { return; + } network_peer->poll(); - if (!network_peer.is_valid()) // It's possible that polling might have resulted in a disconnection, so check here. + if (!network_peer.is_valid()) { // It's possible that polling might have resulted in a disconnection, so check here. return; + } while (network_peer->get_available_packet_count()) { int sender = network_peer->get_packet_peer(); @@ -139,8 +143,9 @@ void MultiplayerAPI::set_root_node(Node *p_node) { } void MultiplayerAPI::set_network_peer(const Ref<NetworkedMultiplayerPeer> &p_peer) { - if (p_peer == network_peer) + if (p_peer == network_peer) { return; // Nothing to do + } ERR_FAIL_COND_MSG(p_peer.is_valid() && p_peer->get_connection_status() == NetworkedMultiplayerPeer::CONNECTION_DISCONNECTED, "Supplied NetworkedMultiplayerPeer must be connecting or connected."); @@ -325,8 +330,9 @@ Node *MultiplayerAPI::_process_get_node(int p_from, const uint8_t *p_packet, uin node = root_node->get_node(np); - if (!node) + if (!node) { ERR_PRINT("Failed to get path from RPC: " + String(np) + "."); + } } else { // Use cached path. int id = p_node_target; @@ -341,8 +347,9 @@ Node *MultiplayerAPI::_process_get_node(int p_from, const uint8_t *p_packet, uin // Do proper caching later. node = root_node->get_node(ni->path); - if (!node) + if (!node) { ERR_PRINT("Failed to get cached path from RPC: " + String(ni->path) + "."); + } } return node; } @@ -529,11 +536,13 @@ bool MultiplayerAPI::_send_confirm_path(Node *p_node, NodePath p_path, PathSentC List<int> peers_to_add; // If one is missing, take note to add it. for (Set<int>::Element *E = connected_peers.front(); E; E = E->next()) { - if (p_target < 0 && E->get() == -p_target) + if (p_target < 0 && E->get() == -p_target) { continue; // Continue, excluded. + } - if (p_target > 0 && E->get() != p_target) + if (p_target > 0 && E->get() != p_target) { continue; // Continue, not for this peer. + } Map<int, bool>::Element *F = psc->confirmed_peers.find(E->get()); @@ -658,8 +667,9 @@ Error MultiplayerAPI::_encode_and_compress_variant(const Variant &p_variant, uin default: // Any other case is not yet compressed. Error err = encode_variant(p_variant, r_buffer, r_len, allow_object_decoding); - if (err != OK) + if (err != OK) { return err; + } if (r_buffer) { // The first byte is not used by the marshaling, so store the type // so we know how to decompress and decode this variant. @@ -684,48 +694,55 @@ Error MultiplayerAPI::_decode_and_decompress_variant(Variant &r_variant, const u case Variant::BOOL: { bool val = (buf[0] & VARIANT_META_BOOL_MASK) > 0; r_variant = val; - if (r_len) + if (r_len) { *r_len = 1; + } } break; case Variant::INT: { buf += 1; len -= 1; - if (r_len) + if (r_len) { *r_len = 1; + } if (encode_mode == ENCODE_8) { // 8 bits. ERR_FAIL_COND_V(len < 1, ERR_INVALID_DATA); int8_t val = buf[0]; r_variant = val; - if (r_len) + if (r_len) { (*r_len) += 1; + } } else if (encode_mode == ENCODE_16) { // 16 bits. ERR_FAIL_COND_V(len < 2, ERR_INVALID_DATA); int16_t val = decode_uint16(buf); r_variant = val; - if (r_len) + if (r_len) { (*r_len) += 2; + } } else if (encode_mode == ENCODE_32) { // 32 bits. ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); int32_t val = decode_uint32(buf); r_variant = val; - if (r_len) + if (r_len) { (*r_len) += 4; + } } else { // 64 bits. ERR_FAIL_COND_V(len < 8, ERR_INVALID_DATA); int64_t val = decode_uint64(buf); r_variant = val; - if (r_len) + if (r_len) { (*r_len) += 8; + } } } break; default: Error err = decode_variant(r_variant, p_buffer, p_len, r_len, allow_object_decoding); - if (err != OK) + if (err != OK) { return err; + } } return OK; @@ -925,11 +942,13 @@ void MultiplayerAPI::_send_rpc(Node *p_from, int p_to, bool p_unreliable, bool p encode_cstring(pname.get_data(), &(packet_cache.write[ofs])); for (Set<int>::Element *E = connected_peers.front(); E; E = E->next()) { - if (p_to < 0 && E->get() == -p_to) + if (p_to < 0 && E->get() == -p_to) { continue; // Continue, excluded. + } - if (p_to > 0 && E->get() != p_to) + if (p_to > 0 && E->get() != p_to) { continue; // Continue, not for this peer. + } Map<int, bool>::Element *F = psc->confirmed_peers.find(E->get()); ERR_CONTINUE(!F); // Should never happen. diff --git a/core/io/net_socket.cpp b/core/io/net_socket.cpp index e92bc705ce..130a2e245e 100644 --- a/core/io/net_socket.cpp +++ b/core/io/net_socket.cpp @@ -33,8 +33,9 @@ NetSocket *(*NetSocket::_create)() = nullptr; NetSocket *NetSocket::create() { - if (_create) + if (_create) { return _create(); + } ERR_PRINT("Unable to create network socket, platform not supported"); return nullptr; diff --git a/core/io/packet_peer.cpp b/core/io/packet_peer.cpp index fe1c9a2eb1..6d37d95994 100644 --- a/core/io/packet_peer.cpp +++ b/core/io/packet_peer.cpp @@ -50,24 +50,28 @@ Error PacketPeer::get_packet_buffer(Vector<uint8_t> &r_buffer) { const uint8_t *buffer; int buffer_size; Error err = get_packet(&buffer, buffer_size); - if (err) + if (err) { return err; + } r_buffer.resize(buffer_size); - if (buffer_size == 0) + if (buffer_size == 0) { return OK; + } uint8_t *w = r_buffer.ptrw(); - for (int i = 0; i < buffer_size; i++) + for (int i = 0; i < buffer_size; i++) { w[i] = buffer[i]; + } return OK; } Error PacketPeer::put_packet_buffer(const Vector<uint8_t> &p_buffer) { int len = p_buffer.size(); - if (len == 0) + if (len == 0) { return OK; + } const uint8_t *r = p_buffer.ptr(); return put_packet(&r[0], len); @@ -77,8 +81,9 @@ Error PacketPeer::get_var(Variant &r_variant, bool p_allow_objects) { const uint8_t *buffer; int buffer_size; Error err = get_packet(&buffer, buffer_size); - if (err) + if (err) { return err; + } return decode_variant(r_variant, buffer, buffer_size, nullptr, p_allow_objects); } @@ -86,11 +91,13 @@ Error PacketPeer::get_var(Variant &r_variant, bool p_allow_objects) { Error PacketPeer::put_var(const Variant &p_packet, bool p_full_objects) { int len; Error err = encode_variant(p_packet, nullptr, len, p_full_objects); // compute len first - if (err) + if (err) { return err; + } - if (len == 0) + if (len == 0) { return OK; + } ERR_FAIL_COND_V_MSG(len > encode_buffer_max_size, ERR_OUT_OF_MEMORY, "Failed to encode variant, encode size is bigger then encode_buffer_max_size. Consider raising it via 'set_encode_buffer_max_size'."); @@ -168,10 +175,12 @@ Error PacketPeerStream::_poll_buffer() const { int read = 0; ERR_FAIL_COND_V(input_buffer.size() < ring_buffer.space_left(), ERR_UNAVAILABLE); Error err = peer->get_partial_data(input_buffer.ptrw(), ring_buffer.space_left(), read); - if (err) + if (err) { return err; - if (read == 0) + } + if (read == 0) { return OK; + } int w = ring_buffer.write(&input_buffer[0], read); ERR_FAIL_COND_V(w != read, ERR_BUG); @@ -193,8 +202,9 @@ int PacketPeerStream::get_available_packet_count() const { uint32_t len = decode_uint32(lbuf); remaining -= 4; ofs += 4; - if (len > remaining) + if (len > remaining) { break; + } remaining -= len; ofs += len; count++; @@ -228,19 +238,22 @@ Error PacketPeerStream::put_packet(const uint8_t *p_buffer, int p_buffer_size) { ERR_FAIL_COND_V(peer.is_null(), ERR_UNCONFIGURED); Error err = _poll_buffer(); //won't hurt to poll here too - if (err) + if (err) { return err; + } - if (p_buffer_size == 0) + if (p_buffer_size == 0) { return OK; + } ERR_FAIL_COND_V(p_buffer_size < 0, ERR_INVALID_PARAMETER); ERR_FAIL_COND_V(p_buffer_size + 4 > output_buffer.size(), ERR_INVALID_PARAMETER); encode_uint32(p_buffer_size, output_buffer.ptrw()); uint8_t *dst = &output_buffer.write[4]; - for (int i = 0; i < p_buffer_size; i++) + for (int i = 0; i < p_buffer_size; i++) { dst[i] = p_buffer[i]; + } return peer->put_data(&output_buffer[0], p_buffer_size + 4); } diff --git a/core/io/packet_peer_udp.cpp b/core/io/packet_peer_udp.cpp index e36de8c228..862fca96fc 100644 --- a/core/io/packet_peer_udp.cpp +++ b/core/io/packet_peer_udp.cpp @@ -38,8 +38,9 @@ void PacketPeerUDP::set_blocking_mode(bool p_enable) { void PacketPeerUDP::set_broadcast_enabled(bool p_enabled) { broadcast = p_enabled; - if (_sock.is_valid() && _sock->is_open()) + if (_sock.is_valid() && _sock->is_open()) { _sock->set_broadcasting_enabled(p_enabled); + } } Error PacketPeerUDP::join_multicast_group(IP_Address p_multi_address, String p_if_name) { @@ -72,8 +73,9 @@ Error PacketPeerUDP::_set_dest_address(const String &p_address, int p_port) { ip = p_address; } else { ip = IP::get_singleton()->resolve_hostname(p_address); - if (!ip.is_valid()) + if (!ip.is_valid()) { return ERR_CANT_RESOLVE; + } } set_dest_address(ip, p_port); @@ -83,18 +85,21 @@ Error PacketPeerUDP::_set_dest_address(const String &p_address, int p_port) { int PacketPeerUDP::get_available_packet_count() const { // TODO we should deprecate this, and expose poll instead! Error err = const_cast<PacketPeerUDP *>(this)->_poll(); - if (err != OK) + if (err != OK) { return -1; + } return queue_count; } Error PacketPeerUDP::get_packet(const uint8_t **r_buffer, int &r_buffer_size) { Error err = _poll(); - if (err != OK) + if (err != OK) { return err; - if (queue_count == 0) + } + if (queue_count == 0) { return ERR_UNAVAILABLE; + } uint32_t size = 0; uint8_t ipv6[16]; @@ -131,10 +136,11 @@ Error PacketPeerUDP::put_packet(const uint8_t *p_buffer, int p_buffer_size) { err = _sock->sendto(p_buffer, p_buffer_size, sent, peer_addr, peer_port); } if (err != OK) { - if (err != ERR_BUSY) + if (err != ERR_BUSY) { return FAILED; - else if (!blocking) + } else if (!blocking) { return ERR_BUSY; + } // Keep trying to send full packet continue; } @@ -157,13 +163,15 @@ Error PacketPeerUDP::listen(int p_port, const IP_Address &p_bind_address, int p_ Error err; IP::Type ip_type = IP::TYPE_ANY; - if (p_bind_address.is_valid()) + if (p_bind_address.is_valid()) { ip_type = p_bind_address.is_ipv4() ? IP::TYPE_IPV4 : IP::TYPE_IPV6; + } err = _sock->open(NetSocket::TYPE_UDP, ip_type); - if (err != OK) + if (err != OK) { return ERR_CANT_CREATE; + } _sock->set_blocking_enabled(false); _sock->set_reuse_address_enabled(true); @@ -235,8 +243,9 @@ bool PacketPeerUDP::is_connected_to_host() const { } void PacketPeerUDP::close() { - if (_sock.is_valid()) + if (_sock.is_valid()) { _sock->close(); + } rb.resize(16); queue_count = 0; connected = false; @@ -269,8 +278,9 @@ Error PacketPeerUDP::_poll() { } if (err != OK) { - if (err == ERR_BUSY) + if (err == ERR_BUSY) { break; + } return FAILED; } diff --git a/core/io/pck_packer.cpp b/core/io/pck_packer.cpp index 4863cd1dbb..06d22ce897 100644 --- a/core/io/pck_packer.cpp +++ b/core/io/pck_packer.cpp @@ -35,14 +35,16 @@ #include "core/version.h" static uint64_t _align(uint64_t p_n, int p_alignment) { - if (p_alignment == 0) + if (p_alignment == 0) { return p_n; + } uint64_t rest = p_n % p_alignment; - if (rest == 0) + if (rest == 0) { return p_n; - else + } else { return p_n + (p_alignment - rest); + } }; static void _pad(FileAccess *p_file, int p_bytes) { @@ -160,8 +162,9 @@ Error PCKPacker::flush(bool p_verbose) { }; }; - if (p_verbose) + if (p_verbose) { printf("\n"); + } file->close(); memdelete_arr(buf); diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index 230925c29b..5097f6d98b 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -96,8 +96,9 @@ enum { void ResourceLoaderBinary::_advance_padding(uint32_t p_len) { uint32_t extra = 4 - (p_len % 4); if (extra < 4) { - for (uint32_t i = 0; i < extra; i++) + for (uint32_t i = 0; i < extra; i++) { f->get_8(); //pad to 32 + } } } @@ -108,8 +109,9 @@ StringName ResourceLoaderBinary::_get_string() { if ((int)len > str_buf.size()) { str_buf.resize(len); } - if (len == 0) + if (len == 0) { return StringName(); + } f->get_buffer((uint8_t *)&str_buf[0], len); String s; s.parse_utf8(&str_buf[0]); @@ -286,10 +288,12 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) { subname_count += 1; // has a property field, so we should count it as well } - for (int i = 0; i < name_count; i++) + for (int i = 0; i < name_count; i++) { names.push_back(_get_string()); - for (uint32_t i = 0; i < subname_count; i++) + } + for (uint32_t i = 0; i < subname_count; i++) { subnames.push_back(_get_string()); + } NodePath np = NodePath(names, subnames, absolute); @@ -512,8 +516,9 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) { Vector<String> array; array.resize(len); String *w = array.ptrw(); - for (uint32_t i = 0; i < len; i++) + for (uint32_t i = 0; i < len; i++) { w[i] = get_unicode_string(); + } r_v = array; @@ -609,8 +614,9 @@ Ref<Resource> ResourceLoaderBinary::get_resource() { } Error ResourceLoaderBinary::load() { - if (error != OK) + if (error != OK) { return error; + } int stage = 0; @@ -680,8 +686,9 @@ Error ResourceLoaderBinary::load() { } } } else { - if (!use_nocache && !ResourceCache::has(res_path)) + if (!use_nocache && !ResourceCache::has(res_path)) { path = res_path; + } } uint64_t offset = internal_resources[i].offset; @@ -730,8 +737,9 @@ Error ResourceLoaderBinary::load() { Variant value; error = parse_variant(value); - if (error) + if (error) { return error; + } res->set(name, value); } @@ -783,8 +791,9 @@ String ResourceLoaderBinary::get_unicode_string() { if (len > str_buf.size()) { str_buf.resize(len); } - if (len == 0) + if (len == 0) { return String(); + } f->get_buffer((uint8_t *)&str_buf[0], len); String s; s.parse_utf8(&str_buf[0]); @@ -793,8 +802,9 @@ String ResourceLoaderBinary::get_unicode_string() { void ResourceLoaderBinary::get_dependencies(FileAccess *p_f, List<String> *p_dependencies, bool p_add_types) { open(p_f); - if (error) + if (error) { return; + } for (int i = 0; i < external_resources.size(); i++) { String dep = external_resources[i].path; @@ -861,8 +871,9 @@ void ResourceLoaderBinary::open(FileAccess *p_f) { print_bl("type: " + type); importmd_ofs = f->get_64(); - for (int i = 0; i < 14; i++) + for (int i = 0; i < 14; i++) { f->get_32(); //skip a few reserved fields + } uint32_t string_table_size = f->get_32(); string_map.resize(string_table_size); @@ -946,13 +957,15 @@ String ResourceLoaderBinary::recognize(FileAccess *p_f) { } ResourceLoaderBinary::~ResourceLoaderBinary() { - if (f) + if (f) { memdelete(f); + } } RES ResourceFormatLoaderBinary::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { - if (r_error) + if (r_error) { *r_error = ERR_FILE_CANT_OPEN; + } Error err; FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err); @@ -1240,8 +1253,9 @@ String ResourceFormatLoaderBinary::get_resource_type(const String &p_path) const void ResourceFormatSaverBinaryInstance::_pad_buffer(FileAccess *f, int p_bytes) { int extra = 4 - (p_bytes % 4); if (extra < 4) { - for (int i = 0; i < extra; i++) + for (int i = 0; i < extra; i++) { f->store_8(0); //pad to 32 + } } } @@ -1430,8 +1444,9 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia NodePath np = p_property; f->store_16(np.get_name_count()); uint16_t snc = np.get_subname_count(); - if (np.is_absolute()) + if (np.is_absolute()) { snc |= 0x8000; + } f->store_16(snc); for (int i = 0; i < np.get_name_count(); i++) { if (string_map.has(np.get_name(i))) { @@ -1531,8 +1546,9 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia int len = arr.size(); f->store_32(len); const int32_t *r = arr.ptr(); - for (int i = 0; i < len; i++) + for (int i = 0; i < len; i++) { f->store_32(r[i]); + } } break; case Variant::PACKED_INT64_ARRAY: { @@ -1541,8 +1557,9 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia int len = arr.size(); f->store_32(len); const int64_t *r = arr.ptr(); - for (int i = 0; i < len; i++) + for (int i = 0; i < len; i++) { f->store_64(r[i]); + } } break; case Variant::PACKED_FLOAT32_ARRAY: { @@ -1628,8 +1645,9 @@ void ResourceFormatSaverBinaryInstance::_find_resources(const Variant &p_variant case Variant::OBJECT: { RES res = p_variant; - if (res.is_null() || external_resources.has(res)) + if (res.is_null() || external_resources.has(res)) { return; + } if (!p_main && (!bundle_resources) && res->get_path().length() && res->get_path().find("::") == -1) { if (res->get_path() == path) { @@ -1641,8 +1659,9 @@ void ResourceFormatSaverBinaryInstance::_find_resources(const Variant &p_variant return; } - if (resource_set.has(res)) + if (resource_set.has(res)) { return; + } List<PropertyInfo> property_list; @@ -1695,10 +1714,12 @@ void ResourceFormatSaverBinaryInstance::_find_resources(const Variant &p_variant case Variant::NODE_PATH: { //take the chance and save node path strings NodePath np = p_variant; - for (int i = 0; i < np.get_name_count(); i++) + for (int i = 0; i < np.get_name_count(); i++) { get_string_index(np.get_name(i)); - for (int i = 0; i < np.get_subname_count(); i++) + } + for (int i = 0; i < np.get_subname_count(); i++) { get_string_index(np.get_subname(i)); + } } break; default: { @@ -1718,8 +1739,9 @@ void ResourceFormatSaverBinaryInstance::save_unicode_string(FileAccess *f, const int ResourceFormatSaverBinaryInstance::get_string_index(const String &p_string) { StringName s = p_string; - if (string_map.has(s)) + if (string_map.has(s)) { return string_map[s]; + } string_map[s] = strings.size(); strings.push_back(s); @@ -1733,8 +1755,9 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p fac->configure("RSCC"); f = fac; err = fac->_open(p_path, FileAccess::WRITE); - if (err) + if (err) { memdelete(f); + } } else { f = FileAccess::open(p_path, FileAccess::WRITE, &err); @@ -1748,8 +1771,9 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p big_endian = p_flags & ResourceSaver::FLAG_SAVE_BIG_ENDIAN; takeover_paths = p_flags & ResourceSaver::FLAG_REPLACE_SUBRESOURCE_PATHS; - if (!p_path.begins_with("res://")) + if (!p_path.begins_with("res://")) { takeover_paths = false; + } local_path = p_path.get_base_dir(); path = ProjectSettings::get_singleton()->localize_path(p_path); @@ -1765,8 +1789,9 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p if (big_endian) { f->store_32(1); f->set_endian_swap(true); - } else + } else { f->store_32(0); + } f->store_32(0); //64 bits file, false for now f->store_32(VERSION_MAJOR); @@ -1781,8 +1806,9 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p save_unicode_string(f, p_resource->get_class()); f->store_64(0); //offset to import metadata - for (int i = 0; i < 14; i++) + for (int i = 0; i < 14; i++) { f->store_32(0); // reserved + } List<ResourceData> resources; @@ -1795,8 +1821,9 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p E->get()->get_property_list(&property_list); for (List<PropertyInfo>::Element *F = property_list.front(); F; F = F->next()) { - if (skip_editor && F->get().name.begins_with("__editor")) + if (skip_editor && F->get().name.begins_with("__editor")) { continue; + } if ((F->get().usage & PROPERTY_USAGE_STORAGE)) { Property p; p.name_idx = get_string_index(F->get().name); @@ -1942,8 +1969,9 @@ bool ResourceFormatSaverBinary::recognize(const RES &p_resource) const { void ResourceFormatSaverBinary::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const { String base = p_resource->get_base_extension().to_lower(); p_extensions->push_back(base); - if (base != "res") + if (base != "res") { p_extensions->push_back("res"); + } } ResourceFormatSaverBinary *ResourceFormatSaverBinary::singleton = nullptr; diff --git a/core/io/resource_importer.cpp b/core/io/resource_importer.cpp index c2e27bc9c2..9ed159bd20 100644 --- a/core/io/resource_importer.cpp +++ b/core/io/resource_importer.cpp @@ -120,8 +120,9 @@ RES ResourceFormatImporter::load(const String &p_path, const String &p_original_ Error err = _get_path_and_type(p_path, pat); if (err != OK) { - if (r_error) + if (r_error) { *r_error = err; + } return RES(); } @@ -163,11 +164,13 @@ void ResourceFormatImporter::get_recognized_extensions_for_type(const String &p_ for (int i = 0; i < importers.size(); i++) { String res_type = importers[i]->get_resource_type(); - if (res_type == String()) + if (res_type == String()) { continue; + } - if (!ClassDB::is_parent_class(res_type, p_type)) + if (!ClassDB::is_parent_class(res_type, p_type)) { continue; + } List<String> local_exts; importers[i]->get_recognized_extensions(&local_exts); @@ -206,8 +209,9 @@ int ResourceFormatImporter::get_import_order(const String &p_path) const { importer = get_importer_by_extension(p_path.get_extension().to_lower()); } - if (importer.is_valid()) + if (importer.is_valid()) { return importer->get_import_order(); + } return 0; } @@ -215,10 +219,12 @@ int ResourceFormatImporter::get_import_order(const String &p_path) const { bool ResourceFormatImporter::handles_type(const String &p_type) const { for (int i = 0; i < importers.size(); i++) { String res_type = importers[i]->get_resource_type(); - if (res_type == String()) + if (res_type == String()) { continue; - if (ClassDB::is_parent_class(res_type, p_type)) + } + if (ClassDB::is_parent_class(res_type, p_type)) { return true; + } } return true; @@ -239,8 +245,9 @@ void ResourceFormatImporter::get_internal_resource_path_list(const String &p_pat Error err; FileAccess *f = FileAccess::open(p_path + ".import", FileAccess::READ, &err); - if (!f) + if (!f) { return; + } VariantParser::StreamFile stream; stream.f = f; diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp index 8490cb5627..f9d2c9067c 100644 --- a/core/io/resource_loader.cpp +++ b/core/io/resource_loader.cpp @@ -59,8 +59,9 @@ bool ResourceFormatLoader::recognize_path(const String &p_path, const String &p_ } for (List<String>::Element *E = extensions.front(); E; E = E->next()) { - if (E->get().nocasecmp_to(extension) == 0) + if (E->get().nocasecmp_to(extension) == 0) { return true; + } } return false; @@ -84,8 +85,9 @@ String ResourceFormatLoader::get_resource_type(const String &p_path) const { } void ResourceFormatLoader::get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) const { - if (p_type == "" || handles_type(p_type)) + if (p_type == "" || handles_type(p_type)) { get_recognized_extensions(p_extensions); + } } void ResourceLoader::get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) { @@ -116,12 +118,14 @@ RES ResourceFormatLoader::load(const String &p_path, const String &p_original_pa Variant res = get_script_instance()->call("load", p_path, p_original_path, p_use_sub_threads); if (res.get_type() == Variant::INT) { - if (r_error) + if (r_error) { *r_error = (Error)res.operator int64_t(); + } } else { - if (r_error) + if (r_error) { *r_error = OK; + } return res; } @@ -240,8 +244,9 @@ void ResourceLoader::_thread_load_function(void *p_userdata) { if (load_task.resource.is_valid()) { load_task.resource->set_path(load_task.local_path); - if (load_task.xl_remapped) + if (load_task.xl_remapped) { load_task.resource->set_as_translation_remapped(true); + } #ifdef TOOLS_ENABLED @@ -263,10 +268,11 @@ void ResourceLoader::_thread_load_function(void *p_userdata) { Error ResourceLoader::load_threaded_request(const String &p_path, const String &p_type_hint, bool p_use_sub_threads, const String &p_source_resource) { String local_path; - if (p_path.is_rel_path()) + if (p_path.is_rel_path()) { local_path = "res://" + p_path; - else + } else { local_path = ProjectSettings::get_singleton()->localize_path(p_path); + } thread_load_mutex->lock(); @@ -392,10 +398,11 @@ float ResourceLoader::_dependency_get_progress(const String &p_path) { ResourceLoader::ThreadLoadStatus ResourceLoader::load_threaded_get_status(const String &p_path, float *r_progress) { String local_path; - if (p_path.is_rel_path()) + if (p_path.is_rel_path()) { local_path = "res://" + p_path; - else + } else { local_path = ProjectSettings::get_singleton()->localize_path(p_path); + } thread_load_mutex->lock(); if (!thread_load_tasks.has(local_path)) { @@ -416,10 +423,11 @@ ResourceLoader::ThreadLoadStatus ResourceLoader::load_threaded_get_status(const RES ResourceLoader::load_threaded_get(const String &p_path, Error *r_error) { String local_path; - if (p_path.is_rel_path()) + if (p_path.is_rel_path()) { local_path = "res://" + p_path; - else + } else { local_path = ProjectSettings::get_singleton()->localize_path(p_path); + } thread_load_mutex->lock(); if (!thread_load_tasks.has(local_path)) { @@ -496,14 +504,16 @@ RES ResourceLoader::load_threaded_get(const String &p_path, Error *r_error) { } RES ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p_no_cache, Error *r_error) { - if (r_error) + if (r_error) { *r_error = ERR_CANT_OPEN; + } String local_path; - if (p_path.is_rel_path()) + if (p_path.is_rel_path()) { local_path = "res://" + p_path; - else + } else { local_path = ProjectSettings::get_singleton()->localize_path(p_path); + } if (!p_no_cache) { thread_load_mutex->lock(); @@ -586,8 +596,9 @@ RES ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p return RES(); } - if (xl_remapped) + if (xl_remapped) { res->set_as_translation_remapped(true); + } #ifdef TOOLS_ENABLED @@ -605,10 +616,11 @@ RES ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p bool ResourceLoader::exists(const String &p_path, const String &p_type_hint) { String local_path; - if (p_path.is_rel_path()) + if (p_path.is_rel_path()) { local_path = "res://" + p_path; - else + } else { local_path = ProjectSettings::get_singleton()->localize_path(p_path); + } if (ResourceCache::has(local_path)) { return true; // If cached, it probably exists @@ -623,8 +635,9 @@ bool ResourceLoader::exists(const String &p_path, const String &p_type_hint) { continue; } - if (loader[i]->exists(path)) + if (loader[i]->exists(path)) { return true; + } } return false; @@ -651,8 +664,9 @@ void ResourceLoader::remove_resource_format_loader(Ref<ResourceFormatLoader> p_f // Find loader int i = 0; for (; i < loader_count; ++i) { - if (loader[i] == p_format_loader) + if (loader[i] == p_format_loader) { break; + } } ERR_FAIL_COND(i >= loader_count); // Not found @@ -669,14 +683,16 @@ int ResourceLoader::get_import_order(const String &p_path) { String path = _path_remap(p_path); String local_path; - if (path.is_rel_path()) + if (path.is_rel_path()) { local_path = "res://" + path; - else + } else { local_path = ProjectSettings::get_singleton()->localize_path(path); + } for (int i = 0; i < loader_count; i++) { - if (!loader[i]->recognize_path(local_path)) + if (!loader[i]->recognize_path(local_path)) { continue; + } /* if (p_type_hint!="" && !loader[i]->handles_type(p_type_hint)) continue; @@ -692,14 +708,16 @@ String ResourceLoader::get_import_group_file(const String &p_path) { String path = _path_remap(p_path); String local_path; - if (path.is_rel_path()) + if (path.is_rel_path()) { local_path = "res://" + path; - else + } else { local_path = ProjectSettings::get_singleton()->localize_path(path); + } for (int i = 0; i < loader_count; i++) { - if (!loader[i]->recognize_path(local_path)) + if (!loader[i]->recognize_path(local_path)) { continue; + } /* if (p_type_hint!="" && !loader[i]->handles_type(p_type_hint)) continue; @@ -715,14 +733,16 @@ bool ResourceLoader::is_import_valid(const String &p_path) { String path = _path_remap(p_path); String local_path; - if (path.is_rel_path()) + if (path.is_rel_path()) { local_path = "res://" + path; - else + } else { local_path = ProjectSettings::get_singleton()->localize_path(path); + } for (int i = 0; i < loader_count; i++) { - if (!loader[i]->recognize_path(local_path)) + if (!loader[i]->recognize_path(local_path)) { continue; + } /* if (p_type_hint!="" && !loader[i]->handles_type(p_type_hint)) continue; @@ -738,14 +758,16 @@ bool ResourceLoader::is_imported(const String &p_path) { String path = _path_remap(p_path); String local_path; - if (path.is_rel_path()) + if (path.is_rel_path()) { local_path = "res://" + path; - else + } else { local_path = ProjectSettings::get_singleton()->localize_path(path); + } for (int i = 0; i < loader_count; i++) { - if (!loader[i]->recognize_path(local_path)) + if (!loader[i]->recognize_path(local_path)) { continue; + } /* if (p_type_hint!="" && !loader[i]->handles_type(p_type_hint)) continue; @@ -761,14 +783,16 @@ void ResourceLoader::get_dependencies(const String &p_path, List<String> *p_depe String path = _path_remap(p_path); String local_path; - if (path.is_rel_path()) + if (path.is_rel_path()) { local_path = "res://" + path; - else + } else { local_path = ProjectSettings::get_singleton()->localize_path(path); + } for (int i = 0; i < loader_count; i++) { - if (!loader[i]->recognize_path(local_path)) + if (!loader[i]->recognize_path(local_path)) { continue; + } /* if (p_type_hint!="" && !loader[i]->handles_type(p_type_hint)) continue; @@ -782,14 +806,16 @@ Error ResourceLoader::rename_dependencies(const String &p_path, const Map<String String path = _path_remap(p_path); String local_path; - if (path.is_rel_path()) + if (path.is_rel_path()) { local_path = "res://" + path; - else + } else { local_path = ProjectSettings::get_singleton()->localize_path(path); + } for (int i = 0; i < loader_count; i++) { - if (!loader[i]->recognize_path(local_path)) + if (!loader[i]->recognize_path(local_path)) { continue; + } /* if (p_type_hint!="" && !loader[i]->handles_type(p_type_hint)) continue; @@ -803,10 +829,11 @@ Error ResourceLoader::rename_dependencies(const String &p_path, const Map<String String ResourceLoader::get_resource_type(const String &p_path) { String local_path; - if (p_path.is_rel_path()) + if (p_path.is_rel_path()) { local_path = "res://" + p_path; - else + } else { local_path = ProjectSettings::get_singleton()->localize_path(p_path); + } for (int i = 0; i < loader_count; i++) { String result = loader[i]->get_resource_type(local_path); @@ -951,8 +978,9 @@ void ResourceLoader::reload_translation_remaps() { } void ResourceLoader::load_translation_remaps() { - if (!ProjectSettings::get_singleton()->has_setting("locale/translation_remaps")) + if (!ProjectSettings::get_singleton()->has_setting("locale/translation_remaps")) { return; + } Dictionary remaps = ProjectSettings::get_singleton()->get("locale/translation_remaps"); List<Variant> keys; @@ -974,8 +1002,9 @@ void ResourceLoader::clear_translation_remaps() { } void ResourceLoader::load_path_remaps() { - if (!ProjectSettings::get_singleton()->has_setting("path_remap/remapped_paths")) + if (!ProjectSettings::get_singleton()->has_setting("path_remap/remapped_paths")) { return; + } Vector<String> remaps = ProjectSettings::get_singleton()->get("path_remap/remapped_paths"); int rc = remaps.size(); @@ -1007,8 +1036,9 @@ Ref<ResourceFormatLoader> ResourceLoader::_find_custom_resource_format_loader(St } bool ResourceLoader::add_custom_resource_format_loader(String script_path) { - if (_find_custom_resource_format_loader(script_path).is_valid()) + if (_find_custom_resource_format_loader(script_path).is_valid()) { return false; + } Ref<Resource> res = ResourceLoader::load(script_path); ERR_FAIL_COND_V(res.is_null(), false); @@ -1032,8 +1062,9 @@ bool ResourceLoader::add_custom_resource_format_loader(String script_path) { void ResourceLoader::remove_custom_resource_format_loader(String script_path) { Ref<ResourceFormatLoader> custom_loader = _find_custom_resource_format_loader(script_path); - if (custom_loader.is_valid()) + if (custom_loader.is_valid()) { remove_resource_format_loader(custom_loader); + } } void ResourceLoader::add_custom_loaders() { diff --git a/core/io/resource_loader.h b/core/io/resource_loader.h index 7d1c4b5d90..9322b5273a 100644 --- a/core/io/resource_loader.h +++ b/core/io/resource_loader.h @@ -158,8 +158,9 @@ public: static bool get_timestamp_on_load() { return timestamp_on_load; } static void notify_load_error(const String &p_err) { - if (err_notify) + if (err_notify) { err_notify(err_notify_ud, p_err); + } } static void set_error_notify_func(void *p_ud, ResourceLoadErrorNotify p_err_notify) { err_notify = p_err_notify; @@ -167,8 +168,9 @@ public: } static void notify_dependency_error(const String &p_path, const String &p_dependency, const String &p_type) { - if (dep_err_notify) + if (dep_err_notify) { dep_err_notify(dep_err_notify_ud, p_path, p_dependency, p_type); + } } static void set_dependency_error_notify_func(void *p_ud, DependencyErrorNotify p_err_notify) { dep_err_notify = p_err_notify; diff --git a/core/io/resource_saver.cpp b/core/io/resource_saver.cpp index 445f9d0c37..a8da215b61 100644 --- a/core/io/resource_saver.cpp +++ b/core/io/resource_saver.cpp @@ -86,28 +86,32 @@ Error ResourceSaver::save(const String &p_path, const RES &p_resource, uint32_t Error err = ERR_FILE_UNRECOGNIZED; for (int i = 0; i < saver_count; i++) { - if (!saver[i]->recognize(p_resource)) + if (!saver[i]->recognize(p_resource)) { continue; + } List<String> extensions; bool recognized = false; saver[i]->get_recognized_extensions(p_resource, &extensions); for (List<String>::Element *E = extensions.front(); E; E = E->next()) { - if (E->get().nocasecmp_to(extension) == 0) + if (E->get().nocasecmp_to(extension) == 0) { recognized = true; + } } - if (!recognized) + if (!recognized) { continue; + } String old_path = p_resource->get_path(); String local_path = ProjectSettings::get_singleton()->localize_path(p_path); RES rwcopy = p_resource; - if (p_flags & FLAG_CHANGE_PATH) + if (p_flags & FLAG_CHANGE_PATH) { rwcopy->set_path(local_path); + } err = saver[i]->save(p_path, p_resource, p_flags); @@ -122,11 +126,13 @@ Error ResourceSaver::save(const String &p_path, const RES &p_resource, uint32_t } #endif - if (p_flags & FLAG_CHANGE_PATH) + if (p_flags & FLAG_CHANGE_PATH) { rwcopy->set_path(old_path); + } - if (save_callback && p_path.begins_with("res://")) + if (save_callback && p_path.begins_with("res://")) { save_callback(p_resource, p_path); + } return OK; } @@ -166,8 +172,9 @@ void ResourceSaver::remove_resource_format_saver(Ref<ResourceFormatSaver> p_form // Find saver int i = 0; for (; i < saver_count; ++i) { - if (saver[i] == p_format_saver) + if (saver[i] == p_format_saver) { break; + } } ERR_FAIL_COND(i >= saver_count); // Not found @@ -190,8 +197,9 @@ Ref<ResourceFormatSaver> ResourceSaver::_find_custom_resource_format_saver(Strin } bool ResourceSaver::add_custom_resource_format_saver(String script_path) { - if (_find_custom_resource_format_saver(script_path).is_valid()) + if (_find_custom_resource_format_saver(script_path).is_valid()) { return false; + } Ref<Resource> res = ResourceLoader::load(script_path); ERR_FAIL_COND_V(res.is_null(), false); @@ -215,8 +223,9 @@ bool ResourceSaver::add_custom_resource_format_saver(String script_path) { void ResourceSaver::remove_custom_resource_format_saver(String script_path) { Ref<ResourceFormatSaver> custom_saver = _find_custom_resource_format_saver(script_path); - if (custom_saver.is_valid()) + if (custom_saver.is_valid()) { remove_resource_format_saver(custom_saver); + } } void ResourceSaver::add_custom_savers() { diff --git a/core/io/stream_peer.cpp b/core/io/stream_peer.cpp index e6175e78da..403f61bb24 100644 --- a/core/io/stream_peer.cpp +++ b/core/io/stream_peer.cpp @@ -34,8 +34,9 @@ Error StreamPeer::_put_data(const Vector<uint8_t> &p_data) { int len = p_data.size(); - if (len == 0) + if (len == 0) { return OK; + } const uint8_t *r = p_data.ptr(); return put_data(&r[0], len); } @@ -318,8 +319,9 @@ double StreamPeer::get_double() { } String StreamPeer::get_string(int p_bytes) { - if (p_bytes < 0) + if (p_bytes < 0) { p_bytes = get_u32(); + } ERR_FAIL_COND_V(p_bytes < 0, String()); Vector<char> buf; @@ -332,8 +334,9 @@ String StreamPeer::get_string(int p_bytes) { } String StreamPeer::get_utf8_string(int p_bytes) { - if (p_bytes < 0) + if (p_bytes < 0) { p_bytes = get_u32(); + } ERR_FAIL_COND_V(p_bytes < 0, String()); Vector<uint8_t> buf; @@ -421,8 +424,9 @@ void StreamPeerBuffer::_bind_methods() { } Error StreamPeerBuffer::put_data(const uint8_t *p_data, int p_bytes) { - if (p_bytes <= 0) + if (p_bytes <= 0) { return OK; + } if (pointer + p_bytes > data.size()) { data.resize(pointer + p_bytes); @@ -443,8 +447,9 @@ Error StreamPeerBuffer::put_partial_data(const uint8_t *p_data, int p_bytes, int Error StreamPeerBuffer::get_data(uint8_t *p_buffer, int p_bytes) { int recv; get_partial_data(p_buffer, p_bytes, recv); - if (recv != p_bytes) + if (recv != p_bytes) { return ERR_INVALID_PARAMETER; + } return OK; } diff --git a/core/io/stream_peer_ssl.cpp b/core/io/stream_peer_ssl.cpp index 92c775a565..3dc31c6769 100644 --- a/core/io/stream_peer_ssl.cpp +++ b/core/io/stream_peer_ssl.cpp @@ -35,8 +35,9 @@ StreamPeerSSL *(*StreamPeerSSL::_create)() = nullptr; StreamPeerSSL *StreamPeerSSL::create() { - if (_create) + if (_create) { return _create(); + } return nullptr; } diff --git a/core/io/stream_peer_tcp.cpp b/core/io/stream_peer_tcp.cpp index fd7ffa8458..cce728c30a 100644 --- a/core/io/stream_peer_tcp.cpp +++ b/core/io/stream_peer_tcp.cpp @@ -117,8 +117,9 @@ Error StreamPeerTCP::write(const uint8_t *p_data, int p_bytes, int &r_sent, bool } } - if (!_sock->is_open()) + if (!_sock->is_open()) { return FAILED; + } Error err; int data_to_send = p_bytes; @@ -257,8 +258,9 @@ StreamPeerTCP::Status StreamPeerTCP::get_status() { } void StreamPeerTCP::disconnect_from_host() { - if (_sock.is_valid() && _sock->is_open()) + if (_sock.is_valid() && _sock->is_open()) { _sock->close(); + } timeout = 0; status = STATUS_NONE; @@ -308,8 +310,9 @@ Error StreamPeerTCP::_connect(const String &p_address, int p_port) { ip = p_address; } else { ip = IP::get_singleton()->resolve_hostname(p_address); - if (!ip.is_valid()) + if (!ip.is_valid()) { return ERR_CANT_RESOLVE; + } } return connect_to_host(ip, p_port); diff --git a/core/io/tcp_server.cpp b/core/io/tcp_server.cpp index 706c650d7e..d7061b6bf4 100644 --- a/core/io/tcp_server.cpp +++ b/core/io/tcp_server.cpp @@ -47,8 +47,9 @@ Error TCP_Server::listen(uint16_t p_port, const IP_Address &p_bind_address) { IP::Type ip_type = IP::TYPE_ANY; // If the bind address is valid use its type as the socket type - if (p_bind_address.is_valid()) + if (p_bind_address.is_valid()) { ip_type = p_bind_address.is_ipv4() ? IP::TYPE_IPV4 : IP::TYPE_IPV6; + } err = _sock->open(NetSocket::TYPE_TCP, ip_type); @@ -82,8 +83,9 @@ bool TCP_Server::is_listening() const { bool TCP_Server::is_connection_available() const { ERR_FAIL_COND_V(!_sock.is_valid(), false); - if (!_sock->is_open()) + if (!_sock->is_open()) { return false; + } Error err = _sock->poll(NetSocket::POLL_TYPE_IN, 0); return (err == OK); @@ -99,8 +101,9 @@ Ref<StreamPeerTCP> TCP_Server::take_connection() { IP_Address ip; uint16_t port = 0; ns = _sock->accept(ip, port); - if (!ns.is_valid()) + if (!ns.is_valid()) { return conn; + } conn = Ref<StreamPeerTCP>(memnew(StreamPeerTCP)); conn->accept_socket(ns, ip, port); diff --git a/core/io/translation_loader_po.cpp b/core/io/translation_loader_po.cpp index 5e109699f5..0e0a948953 100644 --- a/core/io/translation_loader_po.cpp +++ b/core/io/translation_loader_po.cpp @@ -47,8 +47,9 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) { String msg_str; String config; - if (r_error) + if (r_error) { *r_error = ERR_FILE_CORRUPT; + } Ref<Translation> translation = Ref<Translation>(memnew(Translation)); int line = 1; @@ -77,10 +78,12 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) { } if (msg_id != "") { - if (!skip_this) + if (!skip_this) { translation->add_message(msg_id, msg_str); - } else if (config == "") + } + } else if (config == "") { config = msg_str; + } l = l.substr(5, l.length()).strip_edges(); status = STATUS_READING_ID; @@ -135,10 +138,11 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) { l = l.substr(0, end_pos); l = l.c_unescape(); - if (status == STATUS_READING_ID) + if (status == STATUS_READING_ID) { msg_id += l; - else + } else { msg_str += l; + } line++; } @@ -148,10 +152,12 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) { if (status == STATUS_READING_STRING) { if (msg_id != "") { - if (!skip_this) + if (!skip_this) { translation->add_message(msg_id, msg_str); - } else if (config == "") + } + } else if (config == "") { config = msg_str; + } } ERR_FAIL_COND_V_MSG(config == "", RES(), "No config found in file: " + f->get_path() + "."); @@ -160,8 +166,9 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) { for (int i = 0; i < configs.size(); i++) { String c = configs[i].strip_edges(); int p = c.find(":"); - if (p == -1) + if (p == -1) { continue; + } String prop = c.substr(0, p).strip_edges(); String value = c.substr(p + 1, c.length()).strip_edges(); @@ -170,15 +177,17 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) { } } - if (r_error) + if (r_error) { *r_error = OK; + } return translation; } RES TranslationLoaderPO::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { - if (r_error) + if (r_error) { *r_error = ERR_CANT_OPEN; + } FileAccess *f = FileAccess::open(p_path, FileAccess::READ); ERR_FAIL_COND_V_MSG(!f, RES(), "Cannot open file '" + p_path + "'."); @@ -196,7 +205,8 @@ bool TranslationLoaderPO::handles_type(const String &p_type) const { } String TranslationLoaderPO::get_resource_type(const String &p_path) const { - if (p_path.get_extension().to_lower() == "po") + if (p_path.get_extension().to_lower() == "po") { return "Translation"; + } return ""; } diff --git a/core/io/udp_server.cpp b/core/io/udp_server.cpp index 40180dcb09..1d329daf8b 100644 --- a/core/io/udp_server.cpp +++ b/core/io/udp_server.cpp @@ -46,13 +46,15 @@ Error UDPServer::listen(uint16_t p_port, const IP_Address &p_bind_address) { Error err; IP::Type ip_type = IP::TYPE_ANY; - if (p_bind_address.is_valid()) + if (p_bind_address.is_valid()) { ip_type = p_bind_address.is_ipv4() ? IP::TYPE_IPV4 : IP::TYPE_IPV6; + } err = _sock->open(NetSocket::TYPE_UDP, ip_type); - if (err != OK) + if (err != OK) { return ERR_CANT_CREATE; + } _sock->set_blocking_enabled(false); _sock->set_reuse_address_enabled(true); @@ -76,8 +78,9 @@ bool UDPServer::is_listening() const { bool UDPServer::is_connection_available() const { ERR_FAIL_COND_V(!_sock.is_valid(), false); - if (!_sock->is_open()) + if (!_sock->is_open()) { return false; + } Error err = _sock->poll(NetSocket::POLL_TYPE_IN, 0); return (err == OK); diff --git a/core/io/xml_parser.cpp b/core/io/xml_parser.cpp index d575e75f0c..11f82fef9d 100644 --- a/core/io/xml_parser.cpp +++ b/core/io/xml_parser.cpp @@ -38,9 +38,11 @@ VARIANT_ENUM_CAST(XMLParser::NodeType); static bool _equalsn(const CharType *str1, const CharType *str2, int len) { int i; - for (i = 0; i < len && str1[i] && str2[i]; ++i) - if (str1[i] != str2[i]) + for (i = 0; i < len && str1[i] && str2[i]; ++i) { + if (str1[i] != str2[i]) { return false; + } + } // if one (or both) of the strings was smaller then they // are only equal if they have the same length @@ -51,8 +53,9 @@ String XMLParser::_replace_special_characters(const String &origstr) { int pos = origstr.find("&"); int oldPos = 0; - if (pos == -1) + if (pos == -1) { return origstr; + } String newstr; @@ -83,8 +86,9 @@ String XMLParser::_replace_special_characters(const String &origstr) { pos = origstr.find("&", pos); } - if (oldPos < origstr.length() - 1) + if (oldPos < origstr.length() - 1) { newstr += (origstr.substr(oldPos, origstr.length() - oldPos)); + } return newstr; } @@ -99,12 +103,15 @@ bool XMLParser::_set_text(char *start, char *end) { // only white space, so that this text won't be reported if (end - start < 3) { char *p = start; - for (; p != end; ++p) - if (!_is_white_space(*p)) + for (; p != end; ++p) { + if (!_is_white_space(*p)) { break; + } + } - if (p == end) + if (p == end) { return false; + } } // set current text to the parsed text, and replace xml special characters @@ -125,8 +132,9 @@ void XMLParser::_parse_closing_xml_element() { ++P; const char *pBeginClose = P; - while (*P != '>') + while (*P != '>') { ++P; + } node_name = String::utf8(pBeginClose, (int)(P - pBeginClose)); #ifdef DEBUG_XML @@ -140,15 +148,17 @@ void XMLParser::_ignore_definition() { char *F = P; // move until end marked with '>' reached - while (*P != '>') + while (*P != '>') { ++P; + } node_name.parse_utf8(F, P - F); ++P; } bool XMLParser::_parse_cdata() { - if (*(P + 1) != '[') + if (*(P + 1) != '[') { return false; + } node_type = NODE_CDATA; @@ -159,8 +169,9 @@ bool XMLParser::_parse_cdata() { ++count; } - if (!*P) + if (!*P) { return true; + } char *cDataBegin = P; char *cDataEnd = nullptr; @@ -176,10 +187,11 @@ bool XMLParser::_parse_cdata() { ++P; } - if (cDataEnd) + if (cDataEnd) { node_name = String::utf8(cDataBegin, (int)(cDataEnd - cDataBegin)); - else + } else { node_name = ""; + } #ifdef DEBUG_XML print_line("XML CDATA: " + node_name); #endif @@ -197,10 +209,11 @@ void XMLParser::_parse_comment() { // move until end of comment reached while (count) { - if (*P == '>') + if (*P == '>') { --count; - else if (*P == '<') + } else if (*P == '<') { ++count; + } ++P; } @@ -222,46 +235,52 @@ void XMLParser::_parse_opening_xml_element() { const char *startName = P; // find end of element - while (*P != '>' && !_is_white_space(*P)) + while (*P != '>' && !_is_white_space(*P)) { ++P; + } const char *endName = P; // find attributes while (*P != '>') { - if (_is_white_space(*P)) + if (_is_white_space(*P)) { ++P; - else { + } else { if (*P != '/') { // we've got an attribute // read the attribute names const char *attributeNameBegin = P; - while (!_is_white_space(*P) && *P != '=') + while (!_is_white_space(*P) && *P != '=') { ++P; + } const char *attributeNameEnd = P; ++P; // read the attribute value // check for quotes and single quotes, thx to murphy - while ((*P != '\"') && (*P != '\'') && *P) + while ((*P != '\"') && (*P != '\'') && *P) { ++P; + } - if (!*P) // malformatted xml file + if (!*P) { // malformatted xml file return; + } const char attributeQuoteChar = *P; ++P; const char *attributeValueBegin = P; - while (*P != attributeQuoteChar && *P) + while (*P != attributeQuoteChar && *P) { ++P; + } - if (!*P) // malformatted xml file + if (!*P) { // malformatted xml file return; + } const char *attributeValueEnd = P; ++P; @@ -304,16 +323,19 @@ void XMLParser::_parse_current_node() { node_offset = P - data; // more forward until '<' found - while (*P != '<' && *P) + while (*P != '<' && *P) { ++P; + } - if (!*P) + if (!*P) { return; + } if (P - start > 0) { // we found some text, store it - if (_set_text(start, P)) + if (_set_text(start, P)) { return; + } } ++P; @@ -327,8 +349,9 @@ void XMLParser::_parse_current_node() { _ignore_definition(); break; case '!': - if (!_parse_cdata()) + if (!_parse_cdata()) { _parse_comment(); + } break; default: _parse_opening_xml_element(); @@ -417,8 +440,9 @@ String XMLParser::get_attribute_value(int p_idx) const { bool XMLParser::has_attribute(const String &p_name) const { for (int i = 0; i < attributes.size(); i++) { - if (attributes[i].name == p_name) + if (attributes[i].name == p_name) { return true; + } } return false; @@ -447,8 +471,9 @@ String XMLParser::get_attribute_value_safe(const String &p_name) const { } } - if (idx < 0) + if (idx < 0) { return ""; + } return attributes[idx].value; } @@ -496,8 +521,9 @@ Error XMLParser::open(const String &p_path) { void XMLParser::skip_section() { // skip if this element is empty anyway. - if (is_empty()) + if (is_empty()) { return; + } // read until we've reached the last element in this section int tagcount = 1; @@ -506,14 +532,16 @@ void XMLParser::skip_section() { if (get_node_type() == XMLParser::NODE_ELEMENT && !is_empty()) { ++tagcount; - } else if (get_node_type() == XMLParser::NODE_ELEMENT_END) + } else if (get_node_type() == XMLParser::NODE_ELEMENT_END) { --tagcount; + } } } void XMLParser::close() { - if (data) + if (data) { memdelete_arr(data); + } data = nullptr; length = 0; P = nullptr; @@ -535,6 +563,7 @@ XMLParser::XMLParser() { } XMLParser::~XMLParser() { - if (data) + if (data) { memdelete_arr(data); + } } diff --git a/core/io/zip_io.cpp b/core/io/zip_io.cpp index 68dd633e70..1979e91b8c 100644 --- a/core/io/zip_io.cpp +++ b/core/io/zip_io.cpp @@ -44,8 +44,9 @@ void *zipio_open(void *data, const char *p_fname, int mode) { f = FileAccess::open(fname, FileAccess::READ); } - if (!f) + if (!f) { return nullptr; + } return data; } |