diff --git a/src/native/CMakeLists.txt b/src/native/CMakeLists.txt index b0cbcc0ae4b..6abbe4f5a03 100644 --- a/src/native/CMakeLists.txt +++ b/src/native/CMakeLists.txt @@ -33,7 +33,7 @@ ensure_variable_set(XA_LIB_TOP_DIR) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${OUTPUT_PATH}/${ANDROID_RID}" CACHE PATH "" FORCE) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${OUTPUT_PATH}/${ANDROID_RID}" CACHE PATH "" FORCE) -set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD 23) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) diff --git a/src/native/monodroid/archive-dso-stub-config.hh.in b/src/native/monodroid/archive-dso-stub-config.hh.in index b0aa77eb3e6..c00d990a244 100644 --- a/src/native/monodroid/archive-dso-stub-config.hh.in +++ b/src/native/monodroid/archive-dso-stub-config.hh.in @@ -5,13 +5,13 @@ namespace xamarin::android { struct ArchiveDSOStubConfig { - static inline constexpr size_t PayloadSectionAlignment = @ARCHIVE_DSO_STUB_PAYLOAD_SECTION_ALIGNMENT@; - static inline constexpr size_t SectionHeaderEntrySize = @SECTION_HEADER_ENTRY_SIZE@; - static inline constexpr size_t SectionHeaderEntryCount = @SECTION_HEADER_ENTRY_COUNT@; - static inline constexpr uint32_t PayloadSectionOffset = @PAYLOAD_SECTION_OFFSET@; + static inline constexpr size_t PayloadSectionAlignment = @ARCHIVE_DSO_STUB_PAYLOAD_SECTION_ALIGNMENT@uz; + static inline constexpr size_t SectionHeaderEntrySize = @SECTION_HEADER_ENTRY_SIZE@uz; + static inline constexpr size_t SectionHeaderEntryCount = @SECTION_HEADER_ENTRY_COUNT@uz; + static inline constexpr uint32_t PayloadSectionOffset = @PAYLOAD_SECTION_OFFSET@uz; // We know that payload section is the last one in the binary, this is an index into // the section header table. - static inline constexpr size_t PayloadSectionIndex = SectionHeaderEntryCount - 1; + static inline constexpr size_t PayloadSectionIndex = SectionHeaderEntryCount - 1uz; }; } diff --git a/src/native/monodroid/embedded-assemblies-zip.cc b/src/native/monodroid/embedded-assemblies-zip.cc index 23aa21f7dda..3f91b71dc9a 100644 --- a/src/native/monodroid/embedded-assemblies-zip.cc +++ b/src/native/monodroid/embedded-assemblies-zip.cc @@ -14,8 +14,6 @@ using namespace xamarin::android::internal; -using read_count_type = size_t; - force_inline bool EmbeddedAssemblies::zip_load_entry_common (size_t entry_index, std::vector const& buf, dynamic_local_string &entry_name, ZipEntryLoadState &state) noexcept { @@ -157,7 +155,7 @@ EmbeddedAssemblies::zip_load_individual_assembly_entries (std::vector c // However, clang-tidy can't know that the value is owned by Mono and we must not free it, thus the suppression. // // NOLINTNEXTLINE(clang-analyzer-unix.Malloc) - for (size_t i = 0; i < num_entries; i++) { + for (size_t i = 0uz; i < num_entries; i++) { bool interesting_entry = zip_load_entry_common (i, buf, entry_name, state); if (!interesting_entry) { continue; @@ -260,7 +258,7 @@ EmbeddedAssemblies::zip_load_assembly_store_entries (std::vector const& bool assembly_store_found = false; log_debug (LOG_ASSEMBLY, "Looking for assembly stores in APK ('%s)", assembly_store_file_path.data ()); - for (size_t i = 0; i < num_entries; i++) { + for (size_t i = 0uz; i < num_entries; i++) { if (all_required_zip_entries_found ()) { need_to_scan_more_apks = false; break; @@ -341,17 +339,17 @@ EmbeddedAssemblies::zip_load_entries (int fd, const char *apk_name, [[maybe_unus .file_name = apk_name, .prefix = prefix, .prefix_len = prefix_len, - .buf_offset = 0, - .compression_method = 0, - .local_header_offset = 0, - .data_offset = 0, - .file_size = 0, + .buf_offset = 0uz, + .compression_method = 0u, + .local_header_offset = 0u, + .data_offset = 0u, + .file_size = 0u, .bundled_assemblies_slow_path = false, - .max_assembly_name_size = 0, - .max_assembly_file_name_size = 0, + .max_assembly_name_size = 0u, + .max_assembly_file_name_size = 0u, }; - ssize_t nread = read (fd, buf.data (), static_cast(buf.size ())); + ssize_t nread = read (fd, buf.data (), buf.size ()); if (static_cast(nread) != cd_size) { Helpers::abort_application ( LOG_ASSEMBLY, @@ -424,14 +422,14 @@ EmbeddedAssemblies::zip_read_cd_info (int fd, uint32_t& cd_offset, uint32_t& cd_ } std::array eocd; - ssize_t nread = ::read (fd, eocd.data (), static_cast(eocd.size ())); + ssize_t nread = ::read (fd, eocd.data (), eocd.size ()); if (nread < 0 || nread != eocd.size ()) { log_error (LOG_ASSEMBLY, "Failed to read EOCD from the APK: %s (nread: %d; errno: %d)", std::strerror (errno), nread, errno); return false; } - size_t index = 0; // signature - std::array signature; + size_t index = 0uz; // signature + std::array signature; if (!zip_read_field (eocd, index, signature)) { log_error (LOG_ASSEMBLY, "Failed to read EOCD signature"); @@ -443,7 +441,7 @@ EmbeddedAssemblies::zip_read_cd_info (int fd, uint32_t& cd_offset, uint32_t& cd_ } // Most probably a ZIP with comment - constexpr size_t alloc_size = 65535 + ZIP_EOCD_LEN; // 64k is the biggest comment size allowed + constexpr size_t alloc_size = 65535uz + ZIP_EOCD_LEN; // 64k is the biggest comment size allowed ret = ::lseek (fd, static_cast(-alloc_size), SEEK_END); if (ret < 0) { log_error (LOG_ASSEMBLY, "Unable to seek into the file to find ECOD before APK comment: %s (ret: %d; errno: %d)", std::strerror (errno), ret, errno); @@ -452,7 +450,7 @@ EmbeddedAssemblies::zip_read_cd_info (int fd, uint32_t& cd_offset, uint32_t& cd_ std::vector buf (alloc_size); - nread = ::read (fd, buf.data (), static_cast(buf.size ())); + nread = ::read (fd, buf.data (), buf.size ()); if (nread < 0 || static_cast(nread) != alloc_size) { log_error (LOG_ASSEMBLY, "Failed to read EOCD and comment from the APK: %s (nread: %d; errno: %d)", std::strerror (errno), nread, errno); @@ -462,7 +460,7 @@ EmbeddedAssemblies::zip_read_cd_info (int fd, uint32_t& cd_offset, uint32_t& cd_ // We scan from the end to save time bool found = false; const uint8_t* data = buf.data (); - for (ssize_t i = static_cast(alloc_size - (ZIP_EOCD_LEN + 2)); i >= 0; i--) { + for (ssize_t i = static_cast(alloc_size - (ZIP_EOCD_LEN + 2)); i >= 0z; i--) { if (memcmp (data + i, ZIP_EOCD_MAGIC.data (), sizeof(ZIP_EOCD_MAGIC)) != 0) continue; @@ -482,8 +480,8 @@ EmbeddedAssemblies::zip_read_cd_info (int fd, uint32_t& cd_offset, uint32_t& cd_ bool EmbeddedAssemblies::zip_adjust_data_offset (int fd, ZipEntryLoadState &state) { - static constexpr size_t LH_FILE_NAME_LENGTH_OFFSET = 26; - static constexpr size_t LH_EXTRA_LENGTH_OFFSET = 28; + static constexpr size_t LH_FILE_NAME_LENGTH_OFFSET = 26uz; + static constexpr size_t LH_EXTRA_LENGTH_OFFSET = 28uz; off_t result = ::lseek (fd, static_cast(state.local_header_offset), SEEK_SET); if (result < 0) { @@ -534,9 +532,9 @@ template bool EmbeddedAssemblies::zip_extract_cd_info (std::array const& buf, uint32_t& cd_offset, uint32_t& cd_size, uint16_t& cd_entries) { - constexpr size_t EOCD_TOTAL_ENTRIES_OFFSET = 10; - constexpr size_t EOCD_CD_SIZE_OFFSET = 12; - constexpr size_t EOCD_CD_START_OFFSET = 16; + constexpr size_t EOCD_TOTAL_ENTRIES_OFFSET = 10uz; + constexpr size_t EOCD_CD_SIZE_OFFSET = 12uz; + constexpr size_t EOCD_CD_START_OFFSET = 16uz; static_assert (BufSize >= ZIP_EOCD_LEN, "Buffer too short for EOCD"); @@ -627,12 +625,12 @@ EmbeddedAssemblies::zip_read_field (T const& buf, size_t index, size_t count, dy bool EmbeddedAssemblies::zip_read_entry_info (std::vector const& buf, dynamic_local_string& file_name, ZipEntryLoadState &state) { - constexpr size_t CD_COMPRESSION_METHOD_OFFSET = 10; - constexpr size_t CD_UNCOMPRESSED_SIZE_OFFSET = 24; - constexpr size_t CD_FILENAME_LENGTH_OFFSET = 28; - constexpr size_t CD_EXTRA_LENGTH_OFFSET = 30; - constexpr size_t CD_LOCAL_HEADER_POS_OFFSET = 42; - constexpr size_t CD_COMMENT_LENGTH_OFFSET = 32; + constexpr size_t CD_COMPRESSION_METHOD_OFFSET = 10uz; + constexpr size_t CD_UNCOMPRESSED_SIZE_OFFSET = 24uz; + constexpr size_t CD_FILENAME_LENGTH_OFFSET = 28uz; + constexpr size_t CD_EXTRA_LENGTH_OFFSET = 30uz; + constexpr size_t CD_LOCAL_HEADER_POS_OFFSET = 42uz; + constexpr size_t CD_COMMENT_LENGTH_OFFSET = 32uz; size_t index = state.buf_offset; zip_ensure_valid_params (buf, index, ZIP_CENTRAL_LEN); diff --git a/src/native/monodroid/embedded-assemblies.cc b/src/native/monodroid/embedded-assemblies.cc index 7f66b345d2a..6a20df0bc59 100644 --- a/src/native/monodroid/embedded-assemblies.cc +++ b/src/native/monodroid/embedded-assemblies.cc @@ -238,8 +238,8 @@ EmbeddedAssemblies::map_runtime_file (XamarinAndroidBundledAssembly& file) noexc if (Util::should_log (LOG_ASSEMBLY) && map_info.area != nullptr) [[unlikely]] { const char *p = (const char*) file.data; - std::array header; - for (size_t j = 0; j < header.size () - 1; ++j) + std::array header; + for (size_t j = 0uz; j < header.size () - 1uz; ++j) header[j] = isprint (p [j]) ? p [j] : '.'; header [header.size () - 1] = '\0'; @@ -349,7 +349,7 @@ EmbeddedAssemblies::individual_assemblies_open_from_bundles (dynamic_local_strin MonoAssembly *a = nullptr; - for (size_t i = 0; i < application_config.number_of_assemblies_in_apk; i++) { + for (size_t i = 0uz; i < application_config.number_of_assemblies_in_apk; i++) { a = load_bundled_assembly (bundled_assemblies [i], name, abi_name, loader_data, ref_only); if (a != nullptr) { return a; @@ -575,7 +575,7 @@ EmbeddedAssemblies::binary_search (const Key *key, const Entry *base, size_t nme force_inline const TypeMapModuleEntry* EmbeddedAssemblies::binary_search (uint32_t key, const TypeMapModuleEntry *arr, uint32_t n) noexcept { - ssize_t left = -1; + ssize_t left = -1z; ssize_t right = static_cast(n); ssize_t middle; @@ -1010,7 +1010,7 @@ EmbeddedAssemblies::typemap_load_index (TypeMapIndexHeader &header, size_t file_ } uint8_t *p = data.get (); - for (size_t i = 0; i < type_map_count; i++) { + for (size_t i = 0uz; i < type_map_count; i++) { type_maps[i].assembly_name = reinterpret_cast(p); p += entry_size; } @@ -1043,7 +1043,7 @@ EmbeddedAssemblies::typemap_load_index (int dir_fd, const char *dir_path, const bool EmbeddedAssemblies::typemap_load_file (BinaryTypeMapHeader &header, const char *dir_path, const char *file_path, int file_fd, TypeMap &module) { - size_t alloc_size = Helpers::add_with_overflow_check (header.assembly_name_length, 1); + size_t alloc_size = Helpers::add_with_overflow_check (header.assembly_name_length, 1uz); module.assembly_name = new char[alloc_size]; ssize_t nread = do_read (file_fd, module.assembly_name, header.assembly_name_length); @@ -1086,7 +1086,7 @@ EmbeddedAssemblies::typemap_load_file (BinaryTypeMapHeader &header, const char * TypeMapEntry *cur; constexpr uint32_t INVALID_TYPE_INDEX = std::numeric_limits::max (); - for (size_t i = 0; i < module.entry_count; i++) { + for (size_t i = 0uz; i < module.entry_count; i++) { cur = const_cast (&module.java_to_managed[i]); cur->from = reinterpret_cast(java_pos); @@ -1291,7 +1291,7 @@ EmbeddedAssemblies::register_from_filesystem (const char *lib_dir_path,bool look ) ); - size_t assembly_count = 0; + size_t assembly_count = 0uz; do { errno = 0; dirent *cur = readdir (lib_dir); diff --git a/src/native/monodroid/embedded-assemblies.hh b/src/native/monodroid/embedded-assemblies.hh index 02c4375fd87..ce9c9068ffe 100644 --- a/src/native/monodroid/embedded-assemblies.hh +++ b/src/native/monodroid/embedded-assemblies.hh @@ -341,7 +341,7 @@ namespace xamarin::android::internal { } template - static const Entry* binary_search (const Key *key, const Entry *base, size_t nmemb, size_t extra_size = 0) noexcept; + static const Entry* binary_search (const Key *key, const Entry *base, size_t nmemb, size_t extra_size = 0uz) noexcept; #if defined (DEBUG) static int compare_type_name (const char *type_name, const TypeMapEntry *entry) noexcept; @@ -390,7 +390,7 @@ namespace xamarin::android::internal { } template - static void unmangle_name (dynamic_local_string &name, size_t start_idx = 0) noexcept + static void unmangle_name (dynamic_local_string &name, size_t start_idx = 0uz) noexcept { constexpr size_t mangled_data_size = get_mangled_data_size (); if (name.length () <= mangled_data_size) { @@ -423,8 +423,8 @@ namespace xamarin::android::internal { bool register_debug_symbols; bool have_and_want_debug_symbols; - size_t bundled_assembly_index = 0; - size_t number_of_found_assemblies = 0; + size_t bundled_assembly_index = 0uz; + size_t number_of_found_assemblies = 0uz; #if defined (DEBUG) TypeMappingInfo *java_to_managed_maps; @@ -436,10 +436,10 @@ namespace xamarin::android::internal { md_mmap_info runtime_config_blob_mmap{}; void *runtime_config_data = nullptr; - size_t runtime_config_data_size = 0; + size_t runtime_config_data_size = 0uz; bool runtime_config_blob_found = false; - uint32_t number_of_mapped_assembly_stores = 0; - uint32_t number_of_zip_dso_entries = 0; + uint32_t number_of_mapped_assembly_stores = 0u; + uint32_t number_of_zip_dso_entries = 0u; bool need_to_scan_more_apks = true; AssemblyStoreIndexEntry *assembly_store_hashes; diff --git a/src/native/monodroid/jni-remapping.cc b/src/native/monodroid/jni-remapping.cc index d566605a3d6..92ffc707573 100644 --- a/src/native/monodroid/jni-remapping.cc +++ b/src/native/monodroid/jni-remapping.cc @@ -28,7 +28,7 @@ JniRemapping::lookup_replacement_type (const char *jniSimpleReference) noexcept } size_t ref_len = strlen (jniSimpleReference); - for (size_t i = 0; i < application_config.jni_remapping_replacement_type_count; i++) { + for (size_t i = 0uz; i < application_config.jni_remapping_replacement_type_count; i++) { JniRemappingTypeReplacementEntry const& entry = jni_remapping_type_replacements[i]; if (equal (entry.name, jniSimpleReference, ref_len)) { @@ -51,7 +51,7 @@ JniRemapping::lookup_replacement_method_info (const char *jniSourceType, const c size_t source_type_len = strlen (jniSourceType); const JniRemappingIndexTypeEntry *type = nullptr; - for (size_t i = 0; i < application_config.jni_remapping_replacement_method_index_entry_count; i++) { + for (size_t i = 0uz; i < application_config.jni_remapping_replacement_method_index_entry_count; i++) { JniRemappingIndexTypeEntry const& entry = jni_remapping_method_replacement_index[i]; if (!equal (entry.name, jniSourceType, source_type_len)) { @@ -67,9 +67,9 @@ JniRemapping::lookup_replacement_method_info (const char *jniSourceType, const c } size_t method_name_len = strlen (jniMethodName); - size_t signature_len = jniMethodSignature == nullptr ? 0 : strlen (jniMethodSignature); + size_t signature_len = jniMethodSignature == nullptr ? 0uz : strlen (jniMethodSignature); - for (size_t i = 0; i < type->method_count; i++) { + for (size_t i = 0uz; i < type->method_count; i++) { JniRemappingIndexMethodEntry const& entry = type->methods[i]; if (!equal (entry.name, jniMethodName, method_name_len)) { @@ -89,7 +89,7 @@ JniRemapping::lookup_replacement_method_info (const char *jniSourceType, const c sig_end--; } - if (equal (entry.signature, jniMethodSignature, static_cast(sig_end - jniMethodSignature) + 1)) { + if (equal (entry.signature, jniMethodSignature, static_cast(sig_end - jniMethodSignature) + 1uz)) { return &type->methods[i].replacement; } } diff --git a/src/native/monodroid/mono-image-loader.hh b/src/native/monodroid/mono-image-loader.hh index 8e1c765128f..783b6af679c 100644 --- a/src/native/monodroid/mono-image-loader.hh +++ b/src/native/monodroid/mono-image-loader.hh @@ -102,7 +102,7 @@ namespace xamarin::android::internal { force_inline static ssize_t find_index (hash_t hash) noexcept { ssize_t idx = Search::binary_search (hash, assembly_image_cache_hashes, number_of_cache_index_entries); - return idx >= 0 ? static_cast(assembly_image_cache_indices[idx]) : -1; + return idx >= 0 ? static_cast(assembly_image_cache_indices[idx]) : -1z; } #endif // def USE_CACHE diff --git a/src/native/monodroid/monodroid-glue-internal.hh b/src/native/monodroid/monodroid-glue-internal.hh index 4bb7caf929b..abbd8a8d4c6 100644 --- a/src/native/monodroid/monodroid-glue-internal.hh +++ b/src/native/monodroid/monodroid-glue-internal.hh @@ -108,7 +108,7 @@ namespace xamarin::android::internal private: static constexpr std::string_view base_apk_name { "/base.apk" }; - static constexpr size_t SMALL_STRING_PARSE_BUFFER_LEN = 50; + static constexpr size_t SMALL_STRING_PARSE_BUFFER_LEN = 50uz; static constexpr bool is_running_on_desktop = false; public: diff --git a/src/native/monodroid/monodroid-glue.cc b/src/native/monodroid/monodroid-glue.cc index d5d1b67d00b..03c8ead558e 100644 --- a/src/native/monodroid/monodroid-glue.cc +++ b/src/native/monodroid/monodroid-glue.cc @@ -157,7 +157,7 @@ MonodroidRuntime::open_from_update_dir (MonoAssemblyName *aname, [[maybe_unused] pname.append (name, name_len); bool is_dll = Util::ends_with (name, SharedConstants::DLL_EXTENSION); - size_t file_name_len = pname.length () + 1; + size_t file_name_len = pname.length () + 1uz; if (!is_dll) file_name_len += SharedConstants::DLL_EXTENSION.length (); @@ -205,7 +205,7 @@ MonodroidRuntime::should_register_file ([[maybe_unused]] const char *filename) return true; } - size_t filename_len = strlen (filename) + 1; // includes space for path separator + size_t filename_len = strlen (filename) + 1uz; // includes space for path separator for (const char *odir : AndroidSystem::override_dirs) { if (odir == nullptr) { continue; @@ -233,7 +233,7 @@ MonodroidRuntime::gather_bundled_assemblies (jstring_array_wrapper &runtimeApks, } int64_t apk_count = static_cast(runtimeApks.get_length ()); - size_t prev_num_assemblies = 0; + size_t prev_num_assemblies = 0uz; bool got_split_config_abi_apk = false; bool got_base_apk = false; @@ -330,11 +330,9 @@ MonodroidRuntime::monodroid_debug_accept (int sock, struct sockaddr_in addr) if (accepted < 0) return -3; - constexpr const char handshake_msg [] = "MonoDroid-Handshake\n"; - constexpr size_t handshake_length = sizeof (handshake_msg) - 1; - + constexpr std::string_view msg { "MonoDroid-Handshake\n" }; do { - res = send (accepted, handshake_msg, handshake_length, 0); + res = send (accepted, msg.data (), msg.size (), 0); } while (res == -1 && errno == EINTR); if (res < 0) return -4; @@ -413,16 +411,16 @@ MonodroidRuntime::parse_runtime_args (dynamic_local_stringdebug = true; if (token.has_at ('=', ARG_DEBUG.length ())) { - constexpr size_t arg_name_length = ARG_DEBUG.length () + 1; // Includes the '=' + constexpr size_t arg_name_length = ARG_DEBUG.length () + 1uz; // Includes the '=' static_local_string hostport (token.length () - arg_name_length); hostport.assign (token.start () + arg_name_length, token.length () - arg_name_length); string_segment address; - size_t field = 0; - while (field < 3 && hostport.next_token (':', address)) { + size_t field = 0uz; + while (field < 3uz && hostport.next_token (':', address)) { switch (field) { - case 0: // host + case 0uz: // host if (address.empty ()) { log_error (LOG_DEFAULT, "Invalid --debug argument for the host field (empty string)"); } else { @@ -430,13 +428,13 @@ MonodroidRuntime::parse_runtime_args (dynamic_local_string more_info { PREFIX }; more_info.append_c (assm_name); @@ -1211,8 +1209,8 @@ MonodroidRuntime::load_assemblies (load_assemblies_context_type ctx, bool preloa total_time_index = internal_timing->start_event (TimingEventKind::AssemblyPreload); } - size_t i = 0; - for (i = 0; i < assemblies.get_length (); ++i) { + size_t i = 0uz; + for (i = 0uz; i < assemblies.get_length (); ++i) { jstring_wrapper &assembly = assemblies [i]; load_assembly (ctx, assembly); // only load the first "main" assembly if we are not preloading. @@ -1224,7 +1222,7 @@ MonodroidRuntime::load_assemblies (load_assemblies_context_type ctx, bool preloa internal_timing->end_event (total_time_index, true /* uses-more_info */); static_local_string more_info; - more_info.append (static_cast(i + 1)); + more_info.append (static_cast(i + 1u)); internal_timing->add_more_info (total_time_index, more_info); } } diff --git a/src/native/monodroid/monodroid-tracing.cc b/src/native/monodroid/monodroid-tracing.cc index 477fa2e7890..7b5c3d9e4f2 100644 --- a/src/native/monodroid/monodroid-tracing.cc +++ b/src/native/monodroid/monodroid-tracing.cc @@ -22,7 +22,7 @@ void MonodroidRuntime::log_traces (JNIEnv *env, TraceKind kind, const char *first_line) noexcept { if (!tracing_init_done) { - std::lock_guard lock (tracing_init_lock); + xamarin::android::lock_guard lock (tracing_init_lock); char *err = nullptr; void *handle = MonodroidDl::monodroid_dlopen (SharedConstants::xamarin_native_tracing_name.data (), MONO_DL_EAGER, &err, nullptr); diff --git a/src/native/monodroid/monovm-properties.cc b/src/native/monodroid/monovm-properties.cc index 8ec3d88f852..50c7c9f569b 100644 --- a/src/native/monodroid/monovm-properties.cc +++ b/src/native/monodroid/monovm-properties.cc @@ -3,9 +3,9 @@ using namespace xamarin::android::internal; MonoVMProperties::property_array MonoVMProperties::_property_keys { - RUNTIME_IDENTIFIER_KEY, - APP_CONTEXT_BASE_DIRECTORY_KEY, - LOCAL_DATE_TIME_OFFSET_KEY, + RUNTIME_IDENTIFIER_KEY.data (), + APP_CONTEXT_BASE_DIRECTORY_KEY.data (), + LOCAL_DATE_TIME_OFFSET_KEY.data (), }; MonoVMProperties::property_array MonoVMProperties::_property_values { diff --git a/src/native/monodroid/monovm-properties.hh b/src/native/monodroid/monovm-properties.hh index 8a9437c738b..2caf946a9e5 100644 --- a/src/native/monodroid/monovm-properties.hh +++ b/src/native/monodroid/monovm-properties.hh @@ -1,8 +1,9 @@ #if !defined (__MONOVM_PROPERTIES_HH) #define __MONOVM_PROPERTIES_HH -#if defined (NET) #include +#include + #include "monodroid-glue-internal.hh" #include "jni-wrappers.hh" @@ -10,16 +11,16 @@ namespace xamarin::android::internal { class MonoVMProperties final { - constexpr static size_t PROPERTY_COUNT = 3; + constexpr static size_t PROPERTY_COUNT = 3uz; - constexpr static char RUNTIME_IDENTIFIER_KEY[] = "RUNTIME_IDENTIFIER"; - constexpr static size_t RUNTIME_IDENTIFIER_INDEX = 0; + constexpr static std::string_view RUNTIME_IDENTIFIER_KEY { "RUNTIME_IDENTIFIER" }; + constexpr static size_t RUNTIME_IDENTIFIER_INDEX = 0uz; - constexpr static char APP_CONTEXT_BASE_DIRECTORY_KEY[] = "APP_CONTEXT_BASE_DIRECTORY"; - constexpr static size_t APP_CONTEXT_BASE_DIRECTORY_INDEX = 1; + constexpr static std::string_view APP_CONTEXT_BASE_DIRECTORY_KEY { "APP_CONTEXT_BASE_DIRECTORY" }; + constexpr static size_t APP_CONTEXT_BASE_DIRECTORY_INDEX = 1uz; - constexpr static char LOCAL_DATE_TIME_OFFSET_KEY[] = "System.TimeZoneInfo.LocalDateTimeOffset"; - constexpr static size_t LOCAL_DATE_TIME_OFFSET_INDEX = 2; + constexpr static std::string_view LOCAL_DATE_TIME_OFFSET_KEY { "System.TimeZoneInfo.LocalDateTimeOffset" }; + constexpr static size_t LOCAL_DATE_TIME_OFFSET_INDEX = 2uz; using property_array = const char*[PROPERTY_COUNT]; @@ -31,7 +32,7 @@ namespace xamarin::android::internal _property_values[APP_CONTEXT_BASE_DIRECTORY_INDEX] = strdup (filesDir.get_cstr ()); - static_local_string<32> localDateTimeOffsetBuffer; + static_local_string<32uz> localDateTimeOffsetBuffer; localDateTimeOffsetBuffer.append (localDateTimeOffset); _property_values[LOCAL_DATE_TIME_OFFSET_INDEX] = strdup (localDateTimeOffsetBuffer.get ()); } @@ -43,7 +44,7 @@ namespace xamarin::android::internal const char* const* property_keys () const { - if constexpr (PROPERTY_COUNT != 0) { + if constexpr (PROPERTY_COUNT != 0uz) { return _property_keys; } else { return nullptr; @@ -52,7 +53,7 @@ namespace xamarin::android::internal const char* const* property_values () const { - if constexpr (PROPERTY_COUNT != 0) { + if constexpr (PROPERTY_COUNT != 0uz) { return _property_values; } else { return nullptr; @@ -67,5 +68,4 @@ namespace xamarin::android::internal constexpr static size_t N_PROPERTY_VALUES = sizeof(_property_values) / sizeof(const char*); }; } -#endif // def NET #endif // ndef __MONOVM_PROPERTIES_HH diff --git a/src/native/monodroid/osbridge.cc b/src/native/monodroid/osbridge.cc index 0bbd1e4b4df..08b4f80b79d 100644 --- a/src/native/monodroid/osbridge.cc +++ b/src/native/monodroid/osbridge.cc @@ -86,9 +86,9 @@ OSBridge::clear_mono_java_gc_bridge_info () int OSBridge::get_gc_bridge_index (MonoClass *klass) { - uint32_t f = 0; + uint32_t f = 0u; - for (size_t i = 0; i < NUM_GC_BRIDGE_TYPES; ++i) { + for (size_t i = 0uz; i < NUM_GC_BRIDGE_TYPES; ++i) { MonoClass *k = mono_java_gc_bridge_info [i].klass; if (k == nullptr) { f++; diff --git a/src/native/monodroid/xamarin-android-app-context.cc b/src/native/monodroid/xamarin-android-app-context.cc index 8fdffd7cbe7..925975c336f 100644 --- a/src/native/monodroid/xamarin-android-app-context.cc +++ b/src/native/monodroid/xamarin-android-app-context.cc @@ -16,7 +16,7 @@ MonodroidRuntime::get_method_name (uint32_t mono_image_index, uint32_t method_to uint64_t id = (static_cast(mono_image_index) << 32) | method_token; log_debug (LOG_ASSEMBLY, "MM: looking for name of method with id 0x%llx, in mono image at index %u", id, mono_image_index); - size_t i = 0; + size_t i = 0uz; while (mm_method_names[i].id != 0) { if (mm_method_names[i].id == id) { return mm_method_names[i].name; diff --git a/src/native/monodroid/xamarin_getifaddrs.cc b/src/native/monodroid/xamarin_getifaddrs.cc index b67472db0cc..17f0f8a7ba6 100644 --- a/src/native/monodroid/xamarin_getifaddrs.cc +++ b/src/native/monodroid/xamarin_getifaddrs.cc @@ -291,7 +291,7 @@ int _monodroid_getifaddrs (struct _monodroid_ifaddrs **ifap) { if (!initialized) { - std::lock_guard lock (init_lock); + xamarin::android::lock_guard lock (init_lock); if (!initialized) { _monodroid_getifaddrs_init (); initialized = true; @@ -533,7 +533,7 @@ parse_netlink_reply (netlink_session *session, struct _monodroid_ifaddrs **ifadd size_t alloc_size = Helpers::multiply_with_overflow_check (sizeof(*response), buf_size); response = (unsigned char*)malloc (alloc_size); - ssize_t length = 0; + ssize_t length = 0z; if (!response) { goto cleanup; } @@ -838,7 +838,7 @@ calculate_address_netmask (struct _monodroid_ifaddrs *ifa, struct ifaddrmsg *net static struct _monodroid_ifaddrs * get_link_address (const struct nlmsghdr *message, struct _monodroid_ifaddrs **ifaddrs_head) { - ssize_t length = 0; + ssize_t length = 0z; struct rtattr *attribute; struct ifaddrmsg *net_address; struct _monodroid_ifaddrs *ifa = NULL; @@ -870,7 +870,7 @@ get_link_address (const struct nlmsghdr *message, struct _monodroid_ifaddrs **if switch (attribute->rta_type) { case IFA_LABEL: { - size_t room_for_trailing_null = 0; + size_t room_for_trailing_null = 0uz; log_debug (LOG_NETLINK, " attribute type: LABEL"); if (payload_size > MAX_IFA_LABEL_SIZE) { diff --git a/src/native/pinvoke-override/pinvoke-override-api-impl.hh b/src/native/pinvoke-override/pinvoke-override-api-impl.hh index 20f57058f17..36523f092a9 100644 --- a/src/native/pinvoke-override/pinvoke-override-api-impl.hh +++ b/src/native/pinvoke-override/pinvoke-override-api-impl.hh @@ -105,8 +105,8 @@ namespace xamarin::android { PinvokeEntry* PinvokeOverride::find_pinvoke_address (hash_t hash, const PinvokeEntry *entries, size_t entry_count) noexcept { - while (entry_count > 0) { - const size_t mid = entry_count / 2; + while (entry_count > 0uz) { + const size_t mid = entry_count / 2uz; const PinvokeEntry *const ret = entries + mid; const std::strong_ordering result = hash <=> ret->hash; @@ -114,7 +114,7 @@ namespace xamarin::android { entry_count = mid; } else if (result > 0) { entries = ret + 1; - entry_count -= mid + 1; + entry_count -= mid + 1uz; } else { return const_cast(ret); } diff --git a/src/native/pinvoke-override/pinvoke-override-api.hh b/src/native/pinvoke-override/pinvoke-override-api.hh index 8ee17540204..445f8cccf0b 100644 --- a/src/native/pinvoke-override/pinvoke-override-api.hh +++ b/src/native/pinvoke-override/pinvoke-override-api.hh @@ -66,7 +66,7 @@ namespace xamarin::android { true >; - static inline constexpr pinvoke_library_map::size_type LIBRARY_MAP_INITIAL_BUCKET_COUNT = 1; + static inline constexpr pinvoke_library_map::size_type LIBRARY_MAP_INITIAL_BUCKET_COUNT = 1uz; public: static void* load_library_symbol (const char *library_name, const char *symbol_name, void **dso_handle = nullptr) noexcept; diff --git a/src/native/pinvoke-override/precompiled.cc b/src/native/pinvoke-override/precompiled.cc index c7496ee2723..1c84095080a 100644 --- a/src/native/pinvoke-override/precompiled.cc +++ b/src/native/pinvoke-override/precompiled.cc @@ -24,7 +24,7 @@ PinvokeOverride::monodroid_pinvoke_override (const char *library_name, const cha if (entry == nullptr) [[unlikely]] { log_fatal (LOG_ASSEMBLY, "Internal p/invoke symbol '%s @ %s' (hash: 0x%zx) not found in compile-time map.", library_name, entrypoint_name, entrypoint_hash); log_fatal (LOG_ASSEMBLY, "compile-time map contents:"); - for (size_t i = 0; i < internal_pinvokes_count; i++) { + for (size_t i = 0uz; i < internal_pinvokes_count; i++) { PinvokeEntry const& e = internal_pinvokes[i]; log_fatal (LOG_ASSEMBLY, "\t'%s'=%p (hash: 0x%zx)", e.name, e.func, e.hash); } diff --git a/src/native/runtime-base/android-system.cc b/src/native/runtime-base/android-system.cc index 2dfdf47d93c..025362628ae 100644 --- a/src/native/runtime-base/android-system.cc +++ b/src/native/runtime-base/android-system.cc @@ -65,21 +65,21 @@ AndroidSystem::lookup_system_property (const char *name, size_t &value_len) noex return nullptr; if (application_config.system_property_count % 2 != 0) { - log_warn (LOG_DEFAULT, "Corrupted environment variable array: does not contain an even number of entries (%u)", application_config.environment_variable_count); + log_warn (LOG_DEFAULT, "Corrupted environment variable array: does not contain an even number of entries (%u)", application_config.system_property_count); return nullptr; } const char *prop_name; const char *prop_value; - for (size_t i = 0; i < application_config.system_property_count; i += 2) { + for (size_t i = 0uz; i < application_config.system_property_count; i += 2uz) { prop_name = app_system_properties[i]; if (prop_name == nullptr || *prop_name == '\0') continue; if (strcmp (prop_name, name) == 0) { - prop_value = app_system_properties [i + 1]; + prop_value = app_system_properties [i + 1uz]; if (prop_value == nullptr || *prop_value == '\0') { - value_len = 0; + value_len = 0uz; return ""; } @@ -107,7 +107,7 @@ AndroidSystem::add_system_property (const char *name, const char *value) noexcep } size_t name_len = strlen (name); - size_t alloc_size = Helpers::add_with_overflow_check (sizeof (BundledProperty), name_len + 1); + size_t alloc_size = Helpers::add_with_overflow_check (sizeof (BundledProperty), name_len + 1uz); p = reinterpret_cast (malloc (alloc_size)); if (p == nullptr) return; @@ -137,7 +137,7 @@ AndroidSystem::_monodroid__system_property_get (const char *name, char *sp_value char *buf = nullptr; if (sp_value_len < PROPERTY_VALUE_BUFFER_LEN) { - size_t alloc_size = Helpers::add_with_overflow_check (PROPERTY_VALUE_BUFFER_LEN, 1); + size_t alloc_size = Helpers::add_with_overflow_check (PROPERTY_VALUE_BUFFER_LEN, 1uz); log_warn (LOG_DEFAULT, "Buffer to store system property may be too small, will copy only %u bytes", sp_value_len); buf = new char [alloc_size]; } @@ -191,7 +191,7 @@ AndroidSystem::monodroid_get_system_property (const char *name, char **value) no } if (len >= 0 && value) { - size_t alloc_size = Helpers::add_with_overflow_check (static_cast(len), 1); + size_t alloc_size = Helpers::add_with_overflow_check (static_cast(len), 1uz); *value = new char [alloc_size]; if (*value == nullptr) return -len; @@ -225,12 +225,12 @@ AndroidSystem::_monodroid_get_system_property_from_file (const char *path, char return file_size + 1; } - size_t alloc_size = Helpers::add_with_overflow_check (file_size, 1); + size_t alloc_size = Helpers::add_with_overflow_check (file_size, 1uz); *value = new char[alloc_size]; size_t len = fread (*value, 1, file_size, fp); fclose (fp); - for (size_t i = 0; i < file_size + 1; ++i) { + for (size_t i = 0uz; i < file_size + 1uz; ++i) { if ((*value) [i] != '\n' && (*value) [i] != '\r') continue; (*value) [i] = 0; @@ -328,7 +328,7 @@ AndroidSystem::load_dso_from_specified_dirs (const char **directories, size_t nu return nullptr; dynamic_local_string full_path; - for (size_t i = 0; i < num_entries; i++) { + for (size_t i = 0uz; i < num_entries; i++) { if (!get_full_dso_path (directories [i], dso_name, full_path)) { continue; } @@ -503,7 +503,7 @@ AndroidSystem::setup_environment_from_override_file (const char *path) noexcept } auto file_size = static_cast(sbuf.st_size); - size_t nread = 0; + size_t nread = 0uz; ssize_t r; auto buf = std::make_unique (file_size); @@ -619,12 +619,12 @@ AndroidSystem::setup_environment () noexcept const char *var_name; const char *var_value; - for (size_t i = 0; i < application_config.environment_variable_count; i += 2) { + for (size_t i = 0uz; i < application_config.environment_variable_count; i += 2) { var_name = app_environment_variables [i]; if (var_name == nullptr || *var_name == '\0') continue; - var_value = app_environment_variables [i + 1]; + var_value = app_environment_variables [i + 1uz]; if (var_value == nullptr) var_value = ""; @@ -698,7 +698,7 @@ AndroidSystem::setup_app_library_directories (jstring_array_wrapper& runtimeApks // dynamically in this case AndroidSystem::app_lib_directories = std::span (single_app_lib_directory); } else { - size_t app_lib_directories_size = have_split_apks ? 1 : runtimeApks.get_length (); + size_t app_lib_directories_size = have_split_apks ? 1uz : runtimeApks.get_length (); AndroidSystem::app_lib_directories = std::span (new const char*[app_lib_directories_size], app_lib_directories_size); } @@ -713,7 +713,7 @@ void AndroidSystem::for_each_apk (jstring_array_wrapper &runtimeApks, ForEachApkHandler handler, void *user_data) noexcept { size_t apksLength = runtimeApks.get_length (); - for (size_t i = 0; i < apksLength; ++i) { + for (size_t i = 0uz; i < apksLength; ++i) { jstring_wrapper &e = runtimeApks [i]; (handler) (e.get_cstr (), i, apksLength, user_data); @@ -733,9 +733,9 @@ force_inline void AndroidSystem::setup_apk_directories (unsigned short running_on_cpu, jstring_array_wrapper &runtimeApks, bool have_split_apks) noexcept { const char *abi = android_abi_names [running_on_cpu]; - size_t number_of_added_directories = 0; + size_t number_of_added_directories = 0uz; - for (size_t i = 0; i < runtimeApks.get_length (); ++i) { + for (size_t i = 0uz; i < runtimeApks.get_length (); ++i) { jstring_wrapper &e = runtimeApks [i]; const char *apk = e.get_cstr (); diff --git a/src/native/runtime-base/android-system.hh b/src/native/runtime-base/android-system.hh index f100c6ff028..3afe52debb3 100644 --- a/src/native/runtime-base/android-system.hh +++ b/src/native/runtime-base/android-system.hh @@ -20,7 +20,7 @@ #include "jni-wrappers.hh" #include "strings.hh" -static inline constexpr size_t PROPERTY_VALUE_BUFFER_LEN = PROP_VALUE_MAX + 1; +static inline constexpr size_t PROPERTY_VALUE_BUFFER_LEN = PROP_VALUE_MAX + 1uz; extern FILE *gref_log; extern FILE *lref_log; diff --git a/src/native/runtime-base/cpu-arch-detect.cc b/src/native/runtime-base/cpu-arch-detect.cc index 601de304beb..d8bcb7dd5fc 100644 --- a/src/native/runtime-base/cpu-arch-detect.cc +++ b/src/native/runtime-base/cpu-arch-detect.cc @@ -5,7 +5,7 @@ #include "cpu-arch.hh" #if __arm__ -static inline constexpr size_t BUF_SIZE = 512; +static inline constexpr size_t BUF_SIZE = 512uz; static int find_in_maps (const char *str) diff --git a/src/native/runtime-base/monodroid-dl.hh b/src/native/runtime-base/monodroid-dl.hh index 00ab2b69138..14455578f0e 100644 --- a/src/native/runtime-base/monodroid-dl.hh +++ b/src/native/runtime-base/monodroid-dl.hh @@ -185,7 +185,7 @@ namespace xamarin::android::internal #if defined (RELEASE) if (AndroidSystem::is_embedded_dso_mode_enabled ()) { DSOApkEntry *apk_entry = dso_apk_entries; - for (size_t i = 0; i < application_config.number_of_shared_libraries; i++) { + for (size_t i = 0uz; i < application_config.number_of_shared_libraries; i++) { if (apk_entry->name_hash != dso->real_name_hash) { apk_entry++; continue; diff --git a/src/native/runtime-base/search.hh b/src/native/runtime-base/search.hh index 2baf54d33d6..9e4c81f1e45 100644 --- a/src/native/runtime-base/search.hh +++ b/src/native/runtime-base/search.hh @@ -16,11 +16,11 @@ namespace xamarin::android::internal { static_assert (equal != nullptr, "equal is a required template parameter"); static_assert (less_than != nullptr, "less_than is a required template parameter"); - ssize_t left = -1; + ssize_t left = -1z; ssize_t right = static_cast(n); while (right - left > 1) { - ssize_t middle = (left + right) >> 1; + ssize_t middle = (left + right) >> 1u; if (less_than (arr[middle], key)) { left = middle; } else { @@ -28,7 +28,7 @@ namespace xamarin::android::internal { } } - return equal (arr[right], key) ? right : -1; + return equal (arr[right], key) ? right : -1z; } force_inline static ssize_t binary_search (hash_t key, const hash_t *arr, size_t n) noexcept diff --git a/src/native/runtime-base/shared-constants.hh b/src/native/runtime-base/shared-constants.hh index d21c99fa79f..5ab84b3ed73 100644 --- a/src/native/runtime-base/shared-constants.hh +++ b/src/native/runtime-base/shared-constants.hh @@ -22,10 +22,10 @@ namespace xamarin::android::internal // These three MUST be the same as like-named constants in src/Xamarin.Android.Build.Tasks/Utilities/MonoAndroidHelper.Basic.cs static constexpr std::string_view MANGLED_ASSEMBLY_NAME_EXT { ".so" }; static constexpr std::string_view MANGLED_ASSEMBLY_REGULAR_ASSEMBLY_MARKER { "lib_" }; - static constexpr size_t REGULAR_ASSEMBLY_MARKER_INDEX = 3; // this ☝️ + static constexpr size_t REGULAR_ASSEMBLY_MARKER_INDEX = 3uz; // this ☝️ static constexpr char REGULAR_ASSEMBLY_MARKER_CHAR = MANGLED_ASSEMBLY_REGULAR_ASSEMBLY_MARKER[REGULAR_ASSEMBLY_MARKER_INDEX]; static constexpr std::string_view MANGLED_ASSEMBLY_SATELLITE_ASSEMBLY_MARKER { "lib-" }; - static constexpr size_t SATELLITE_ASSEMBLY_MARKER_INDEX = 3; // this ☝️ + static constexpr size_t SATELLITE_ASSEMBLY_MARKER_INDEX = 3uz; // this ☝️ static constexpr char SATELLITE_ASSEMBLY_MARKER_CHAR = MANGLED_ASSEMBLY_SATELLITE_ASSEMBLY_MARKER[SATELLITE_ASSEMBLY_MARKER_INDEX]; static constexpr std::string_view MONO_ANDROID_RUNTIME_ASSEMBLY_NAME { "Mono.Android.Runtime" }; @@ -89,16 +89,16 @@ namespace xamarin::android::internal // // Indexes must match these of trhe `appDirs` array in src/java-runtime/mono/android/MonoPackageManager.java // - static constexpr size_t APP_DIRS_FILES_DIR_INDEX = 0; - static constexpr size_t APP_DIRS_CACHE_DIR_INDEX = 1; - static constexpr size_t APP_DIRS_DATA_DIR_INDEX = 2; + static constexpr size_t APP_DIRS_FILES_DIR_INDEX = 0uz; + static constexpr size_t APP_DIRS_CACHE_DIR_INDEX = 1uz; + static constexpr size_t APP_DIRS_DATA_DIR_INDEX = 2uz; // 64-bit unsigned or 64-bit signed with sign - static constexpr size_t MAX_INTEGER_DIGIT_COUNT_BASE10 = 21; - static constexpr size_t INTEGER_BASE10_BUFFER_SIZE = MAX_INTEGER_DIGIT_COUNT_BASE10 + 1; + static constexpr size_t MAX_INTEGER_DIGIT_COUNT_BASE10 = 21uz; + static constexpr size_t INTEGER_BASE10_BUFFER_SIZE = MAX_INTEGER_DIGIT_COUNT_BASE10 + 1uz; // Documented in NDK's comments - static constexpr size_t MAX_LOGCAT_MESSAGE_LENGTH = 1023; + static constexpr size_t MAX_LOGCAT_MESSAGE_LENGTH = 1023uz; static constexpr std::string_view LOG_CATEGORY_NAME_NONE { "*none*" }; static constexpr std::string_view LOG_CATEGORY_NAME_MONODROID { "monodroid" }; diff --git a/src/native/runtime-base/strings.hh b/src/native/runtime-base/strings.hh index 77cf335eb9a..74fe498de4c 100644 --- a/src/native/runtime-base/strings.hh +++ b/src/native/runtime-base/strings.hh @@ -15,8 +15,8 @@ namespace xamarin::android::internal { - static constexpr size_t SENSIBLE_TYPE_NAME_LENGTH = 128; - static constexpr size_t SENSIBLE_PATH_MAX = 256; + static constexpr size_t SENSIBLE_TYPE_NAME_LENGTH = 128uz; + static constexpr size_t SENSIBLE_PATH_MAX = 256uz; #if DEBUG static constexpr bool BoundsCheck = true; @@ -144,14 +144,14 @@ namespace xamarin::android::internal } template - force_inline bool to_integer (T &val, size_t start_index = 0, int base = 10) const noexcept + force_inline bool to_integer (T &val, size_t start_index = 0uz, int base = 10) const noexcept { static_assert (std::is_integral_v); constexpr T min = std::numeric_limits::min (); constexpr T max = std::numeric_limits::max (); using integer = typename std::conditional, int64_t, uint64_t>::type; - if (length () == 0) { + if (length () == 0uz) { return false; } @@ -212,10 +212,10 @@ namespace xamarin::android::internal } protected: - size_t _last_index = 0; + size_t _last_index = 0uz; bool _fresh = true; const char *_start = nullptr; - size_t _length = 0; + size_t _length = 0uz; template friend class string_base; }; @@ -319,7 +319,7 @@ namespace xamarin::android::internal using base = dynamic_local_storage_base; public: - explicit dynamic_local_storage (size_t initial_size = 0) noexcept + explicit dynamic_local_storage (size_t initial_size = 0uz) noexcept : base (initial_size) {} @@ -375,7 +375,7 @@ namespace xamarin::android::internal static constexpr TChar ZERO = '0'; public: - explicit string_base (size_t initial_size = 0) + explicit string_base (size_t initial_size = 0uz) : buffer (initial_size) { // Currently we care only about `char`, maybe in the future we'll add support for `wchar` (if needed) @@ -428,7 +428,7 @@ namespace xamarin::android::internal return *this; } - for (size_t i = 0; i < length (); i++) { + for (size_t i = 0uz; i < length (); i++) { if (buffer.get ()[i] == c1) { buffer.get ()[i] = c2; } @@ -439,7 +439,7 @@ namespace xamarin::android::internal force_inline string_base& append (const TChar* s, size_t length) noexcept { - if (s == nullptr || length == 0) + if (s == nullptr || length == 0uz) return *this; resize_for_extra (length); @@ -713,19 +713,19 @@ namespace xamarin::android::internal if (i == 0) { constexpr char zero[] = "0"; - constexpr size_t zero_len = sizeof(zero) - 1; + constexpr size_t zero_len = sizeof(zero) - 1uz; append (zero, zero_len); return; } - TChar temp_buf[SharedConstants::MAX_INTEGER_DIGIT_COUNT_BASE10 + 1]; + TChar temp_buf[SharedConstants::MAX_INTEGER_DIGIT_COUNT_BASE10 + 1uz]; TChar *p = temp_buf + SharedConstants::MAX_INTEGER_DIGIT_COUNT_BASE10; *p = NUL; TChar *end = p; uint32_t x; - if constexpr (sizeof(Integer) > 4) { + if constexpr (sizeof(Integer) > 4uz) { uint64_t y; if constexpr (std::is_signed_v) { @@ -788,10 +788,10 @@ namespace xamarin::android::internal force_inline void resize_for_extra (size_t needed_space) noexcept { if constexpr (TStorage::has_resize) { - size_t required_space = Helpers::add_with_overflow_check (needed_space, idx + 1); + size_t required_space = Helpers::add_with_overflow_check (needed_space, idx + 1uz); size_t current_size = buffer.size (); if (required_space > current_size) { - size_t new_size = Helpers::add_with_overflow_check (current_size, (current_size / 2)); + size_t new_size = Helpers::add_with_overflow_check (current_size, (current_size / 2uz)); new_size = Helpers::add_with_overflow_check (new_size, required_space); buffer.resize (new_size); } @@ -809,7 +809,7 @@ namespace xamarin::android::internal using base = string_base, TChar>; public: - explicit static_local_string (size_t initial_size = 0) noexcept + explicit static_local_string (size_t initial_size = 0uz) noexcept : base (initial_size) {} @@ -831,7 +831,7 @@ namespace xamarin::android::internal using base = string_base, TChar>; public: - explicit dynamic_local_string (size_t initial_size = 0) + explicit dynamic_local_string (size_t initial_size = 0uz) : base (initial_size) {} diff --git a/src/native/runtime-base/timing-internal.cc b/src/native/runtime-base/timing-internal.cc index 5b91c5186f8..eaaee8c17ef 100644 --- a/src/native/runtime-base/timing-internal.cc +++ b/src/native/runtime-base/timing-internal.cc @@ -45,13 +45,13 @@ FastTiming::dump () noexcept dynamic_local_string message; // Values are in nanoseconds - uint64_t total_assembly_load_time = 0; - uint64_t total_java_to_managed_time = 0; - uint64_t total_managed_to_java_time = 0; + uint64_t total_assembly_load_time = 0u; + uint64_t total_java_to_managed_time = 0u; + uint64_t total_managed_to_java_time = 0u; uint64_t total_ns; format_and_log (init_time, message, total_ns, true /* indent */); - for (size_t i = 0; i < entries; i++) { + for (size_t i = 0uz; i < entries; i++) { TimingEvent const& event = events[i]; format_and_log (event, message, total_ns, true /* indent */); diff --git a/src/native/runtime-base/timing-internal.hh b/src/native/runtime-base/timing-internal.hh index 10da5de5162..4e896c8fc94 100644 --- a/src/native/runtime-base/timing-internal.hh +++ b/src/native/runtime-base/timing-internal.hh @@ -82,9 +82,9 @@ namespace xamarin::android::internal // time of class instantiation. It's an arbitrary value, but it should // be large enough to not require any dynamic reallocation of memory at // the run time. - static constexpr size_t INITIAL_EVENT_VECTOR_SIZE = 4096; - static constexpr uint32_t ns_in_millisecond = 1000000; - static constexpr uint32_t ms_in_second = 1000; + static constexpr size_t INITIAL_EVENT_VECTOR_SIZE = 4096uz; + static constexpr uint32_t ns_in_millisecond = 1000000u; + static constexpr uint32_t ms_in_second = 1000u; static constexpr uint32_t ns_in_second = ms_in_second * ns_in_millisecond; protected: @@ -440,7 +440,7 @@ namespace xamarin::android::internal } private: - std::atomic_size_t next_event_index = 0; + std::atomic_size_t next_event_index = 0uz; xamarin::android::mutex event_vector_realloc_mutex; std::vector events; diff --git a/src/native/runtime-base/timing.hh b/src/native/runtime-base/timing.hh index 8d6b5ff1b0f..815e256252c 100644 --- a/src/native/runtime-base/timing.hh +++ b/src/native/runtime-base/timing.hh @@ -76,7 +76,7 @@ namespace xamarin::android static constexpr char MESSAGE_FORMAT[] = "%s" TIMING_FORMAT; public: - static constexpr size_t DEFAULT_POOL_SIZE = 16; + static constexpr size_t DEFAULT_POOL_SIZE = 16uz; public: explicit Timing (size_t initial_pool_size = DEFAULT_POOL_SIZE) noexcept @@ -109,7 +109,7 @@ namespace xamarin::android lock_guard lock (sequence_lock); managed_timing_sequence *ret; - for (size_t i = 0; i < sequence_pool_size; i++) { + for (size_t i = 0uz; i < sequence_pool_size; i++) { if (sequence_pool[i].in_use) { continue; } diff --git a/src/native/runtime-base/util.cc b/src/native/runtime-base/util.cc index 934ef789da8..7a58a2836c1 100644 --- a/src/native/runtime-base/util.cc +++ b/src/native/runtime-base/util.cc @@ -39,7 +39,7 @@ Util::recv_uninterrupted (int fd, void *buf, size_t len) using nbytes_type = size_t; ssize_t res; - size_t total = 0; + size_t total = 0uz; int flags = 0; nbytes_type nbytes; @@ -47,9 +47,9 @@ Util::recv_uninterrupted (int fd, void *buf, size_t len) nbytes = static_cast(len - total); res = recv (fd, (char *) buf + total, nbytes, flags); - if (res > 0) + if (res > 0z) total += static_cast(res); - } while ((res > 0 && total < len) || (res == -1 && errno == EINTR)); + } while ((res > 0z && total < len) || (res == -1z && errno == EINTR)); return static_cast(total); } @@ -132,13 +132,13 @@ Util::path_combine (const char *path1, const char *path2) if (path2 == nullptr) return strdup_new (path1); - size_t len = Helpers::add_with_overflow_check (strlen (path1), strlen (path2) + 2); + size_t len = Helpers::add_with_overflow_check (strlen (path1), strlen (path2) + 2uz); char *ret = new char [len]; *ret = '\0'; - strncat (ret, path1, len - 1); - strncat (ret, "/", len - 1); - strncat (ret, path2, len - 1); + strncat (ret, path1, len - 1uz); + strncat (ret, "/", len - 1uz); + strncat (ret, path2, len - 1uz); return ret; } @@ -333,7 +333,7 @@ Util::monodroid_strsplit (const char *str, const char *delimiter, size_t max_tok } const char *p_str = str; - size_t tokens_in_str = 0; + size_t tokens_in_str = 0uz; size_t delimiter_len = strlen (delimiter); while (*p_str != '\0') { @@ -347,10 +347,10 @@ Util::monodroid_strsplit (const char *str, const char *delimiter, size_t max_tok p_str += bytes; } - size_t vector_size = (max_tokens > 0 && tokens_in_str >= max_tokens) ? max_tokens + 1 : tokens_in_str + 2; // Includes the terminating 'nullptr` entry + size_t vector_size = (max_tokens > 0uz && tokens_in_str >= max_tokens) ? max_tokens + 1uz : tokens_in_str + 2uz; // Includes the terminating 'nullptr` entry char **vector = static_cast(xmalloc (Helpers::multiply_with_overflow_check (sizeof(char*), vector_size))); - size_t vector_idx = 0; + size_t vector_idx = 0uz; while (*str != '\0' && !(max_tokens > 0 && vector_idx + 1 >= max_tokens)) { const char *c = str; @@ -371,7 +371,7 @@ Util::monodroid_strsplit (const char *str, const char *delimiter, size_t max_tok } size_t toklen = static_cast((str - c)); - size_t alloc_size = Helpers::add_with_overflow_check (toklen, 1); + size_t alloc_size = Helpers::add_with_overflow_check (toklen, 1uz); char *token = static_cast(xmalloc (alloc_size)); strncpy (token, c, toklen); token [toklen] = '\0'; diff --git a/src/native/runtime-base/util.hh b/src/native/runtime-base/util.hh index 718e2e87551..8dd7f432664 100644 --- a/src/native/runtime-base/util.hh +++ b/src/native/runtime-base/util.hh @@ -207,7 +207,7 @@ namespace xamarin::android template static bool ends_with (internal::string_base const& str, const char (&end)[N]) noexcept { - constexpr size_t end_length = N - 1; + constexpr size_t end_length = N - 1uz; size_t len = str.length (); if (len < end_length) [[unlikely]] { @@ -220,7 +220,7 @@ namespace xamarin::android template static bool ends_with (internal::string_base const& str, std::array const& end) noexcept { - constexpr size_t end_length = N - 1; + constexpr size_t end_length = N - 1uz; size_t len = str.length (); if (len < end_length) [[unlikely]] { @@ -233,7 +233,7 @@ namespace xamarin::android template static bool ends_with (internal::string_base const& str, helper_char_array const& end) noexcept { - constexpr size_t end_length = N - 1; + constexpr size_t end_length = N - 1uz; size_t len = str.length (); if (len < end_length) [[unlikely]] { @@ -250,8 +250,8 @@ namespace xamarin::android return nullptr; } - for (size_t i = str.length (); i > 0; i--) { - const size_t index = i - 1; + for (size_t i = str.length (); i > 0uz; i--) { + const size_t index = i - 1uz; if (str[index] == ch) { return str.get () + index; } @@ -304,7 +304,7 @@ namespace xamarin::android return strdup_new (buf.get (), buf.length ()); } - static char *strdup_new (xamarin::android::internal::string_segment const& s, size_t from_index = 0) noexcept + static char *strdup_new (xamarin::android::internal::string_segment const& s, size_t from_index = 0uz) noexcept { if (from_index >= s.length ()) { return nullptr; diff --git a/src/native/shared/cpp-util.hh b/src/native/shared/cpp-util.hh index 9b0922ff927..160fa844e36 100644 --- a/src/native/shared/cpp-util.hh +++ b/src/native/shared/cpp-util.hh @@ -105,7 +105,7 @@ namespace xamarin::android char_array ret; // lgtm [cpp/paddingbyteinformationdisclosure] the buffer is filled in the loop below ret[total_length] = 0; - size_t i = 0; + size_t i = 0uz; for (char const* from : {parts...}) { for (; *from != '\0'; i++) { ret[i] = *from++; diff --git a/src/native/tracing/native-tracing.cc b/src/native/tracing/native-tracing.cc index d1ec536dba3..8f1e9a71324 100644 --- a/src/native/tracing/native-tracing.cc +++ b/src/native/tracing/native-tracing.cc @@ -43,16 +43,16 @@ const char* xa_get_native_backtrace () noexcept unw_context_t uc; unw_word_t ip; unw_word_t offp; - std::array name_buf; - std::array num_buf; // Enough for text representation of a decimal 64-bit integer + some possible - // additions (sign, padding, punctuation etc) + std::array name_buf; + std::array num_buf; // Enough for text representation of a decimal 64-bit integer + some possible + // additions (sign, padding, punctuation etc) const char *symbol_name; Dl_info info; unw_getcontext (&uc); unw_init_local (&cursor, &uc); - size_t frame_counter = 0; + size_t frame_counter = 0uz; std::string trace; while (unw_step (&cursor) > 0) { diff --git a/src/native/xamarin-app-stub/application_dso_stub.cc b/src/native/xamarin-app-stub/application_dso_stub.cc index 37c3e6381ef..f840005c204 100644 --- a/src/native/xamarin-app-stub/application_dso_stub.cc +++ b/src/native/xamarin-app-stub/application_dso_stub.cc @@ -73,7 +73,7 @@ const char* const mono_aot_mode_name = "normal"; const char* const app_environment_variables[] = {}; const char* const app_system_properties[] = {}; -static constexpr size_t AssemblyNameWidth = 128; +static constexpr size_t AssemblyNameWidth = 128uz; static char first_assembly_name[AssemblyNameWidth]; static char second_assembly_name[AssemblyNameWidth];