1414
1515using namespace xamarin ::android::internal;
1616
17- using read_count_type = size_t ;
18-
1917force_inline bool
2018EmbeddedAssemblies::zip_load_entry_common (size_t entry_index, std::vector<uint8_t > const & buf, dynamic_local_string<SENSIBLE_PATH_MAX> &entry_name, ZipEntryLoadState &state) noexcept
2119{
@@ -157,7 +155,7 @@ EmbeddedAssemblies::zip_load_individual_assembly_entries (std::vector<uint8_t> c
157155 // However, clang-tidy can't know that the value is owned by Mono and we must not free it, thus the suppression.
158156 //
159157 // NOLINTNEXTLINE(clang-analyzer-unix.Malloc)
160- for (size_t i = 0 ; i < num_entries; i++) {
158+ for (size_t i = 0uz ; i < num_entries; i++) {
161159 bool interesting_entry = zip_load_entry_common (i, buf, entry_name, state);
162160 if (!interesting_entry) {
163161 continue ;
@@ -260,7 +258,7 @@ EmbeddedAssemblies::zip_load_assembly_store_entries (std::vector<uint8_t> const&
260258 bool assembly_store_found = false ;
261259
262260 log_debug (LOG_ASSEMBLY, " Looking for assembly stores in APK ('%s)" , assembly_store_file_path.data ());
263- for (size_t i = 0 ; i < num_entries; i++) {
261+ for (size_t i = 0uz ; i < num_entries; i++) {
264262 if (all_required_zip_entries_found ()) {
265263 need_to_scan_more_apks = false ;
266264 break ;
@@ -341,17 +339,17 @@ EmbeddedAssemblies::zip_load_entries (int fd, const char *apk_name, [[maybe_unus
341339 .file_name = apk_name,
342340 .prefix = prefix,
343341 .prefix_len = prefix_len,
344- .buf_offset = 0 ,
345- .compression_method = 0 ,
346- .local_header_offset = 0 ,
347- .data_offset = 0 ,
348- .file_size = 0 ,
342+ .buf_offset = 0uz ,
343+ .compression_method = 0u ,
344+ .local_header_offset = 0u ,
345+ .data_offset = 0u ,
346+ .file_size = 0u ,
349347 .bundled_assemblies_slow_path = false ,
350- .max_assembly_name_size = 0 ,
351- .max_assembly_file_name_size = 0 ,
348+ .max_assembly_name_size = 0u ,
349+ .max_assembly_file_name_size = 0u ,
352350 };
353351
354- ssize_t nread = read (fd, buf.data (), static_cast <read_count_type>( buf.size () ));
352+ ssize_t nread = read (fd, buf.data (), buf.size ());
355353 if (static_cast <size_t >(nread) != cd_size) {
356354 Helpers::abort_application (
357355 LOG_ASSEMBLY,
@@ -424,14 +422,14 @@ EmbeddedAssemblies::zip_read_cd_info (int fd, uint32_t& cd_offset, uint32_t& cd_
424422 }
425423
426424 std::array<uint8_t , ZIP_EOCD_LEN> eocd;
427- ssize_t nread = ::read (fd, eocd.data (), static_cast <read_count_type>( eocd.size () ));
425+ ssize_t nread = ::read (fd, eocd.data (), eocd.size ());
428426 if (nread < 0 || nread != eocd.size ()) {
429427 log_error (LOG_ASSEMBLY, " Failed to read EOCD from the APK: %s (nread: %d; errno: %d)" , std::strerror (errno), nread, errno);
430428 return false ;
431429 }
432430
433- size_t index = 0 ; // signature
434- std::array<uint8_t , 4 > signature;
431+ size_t index = 0uz ; // signature
432+ std::array<uint8_t , 4uz > signature;
435433
436434 if (!zip_read_field (eocd, index, signature)) {
437435 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_
443441 }
444442
445443 // Most probably a ZIP with comment
446- constexpr size_t alloc_size = 65535 + ZIP_EOCD_LEN; // 64k is the biggest comment size allowed
444+ constexpr size_t alloc_size = 65535uz + ZIP_EOCD_LEN; // 64k is the biggest comment size allowed
447445 ret = ::lseek (fd, static_cast <off_t >(-alloc_size), SEEK_END);
448446 if (ret < 0 ) {
449447 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_
452450
453451 std::vector<uint8_t > buf (alloc_size);
454452
455- nread = ::read (fd, buf.data (), static_cast <read_count_type>( buf.size () ));
453+ nread = ::read (fd, buf.data (), buf.size ());
456454
457455 if (nread < 0 || static_cast <size_t >(nread) != alloc_size) {
458456 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_
462460 // We scan from the end to save time
463461 bool found = false ;
464462 const uint8_t * data = buf.data ();
465- for (ssize_t i = static_cast <ssize_t >(alloc_size - (ZIP_EOCD_LEN + 2 )); i >= 0 ; i--) {
463+ for (ssize_t i = static_cast <ssize_t >(alloc_size - (ZIP_EOCD_LEN + 2 )); i >= 0z ; i--) {
466464 if (memcmp (data + i, ZIP_EOCD_MAGIC.data (), sizeof (ZIP_EOCD_MAGIC)) != 0 )
467465 continue ;
468466
@@ -482,8 +480,8 @@ EmbeddedAssemblies::zip_read_cd_info (int fd, uint32_t& cd_offset, uint32_t& cd_
482480bool
483481EmbeddedAssemblies::zip_adjust_data_offset (int fd, ZipEntryLoadState &state)
484482{
485- static constexpr size_t LH_FILE_NAME_LENGTH_OFFSET = 26 ;
486- static constexpr size_t LH_EXTRA_LENGTH_OFFSET = 28 ;
483+ static constexpr size_t LH_FILE_NAME_LENGTH_OFFSET = 26uz ;
484+ static constexpr size_t LH_EXTRA_LENGTH_OFFSET = 28uz ;
487485
488486 off_t result = ::lseek (fd, static_cast <off_t >(state.local_header_offset ), SEEK_SET);
489487 if (result < 0 ) {
@@ -534,9 +532,9 @@ template<size_t BufSize>
534532bool
535533EmbeddedAssemblies::zip_extract_cd_info (std::array<uint8_t , BufSize> const & buf, uint32_t & cd_offset, uint32_t & cd_size, uint16_t & cd_entries)
536534{
537- constexpr size_t EOCD_TOTAL_ENTRIES_OFFSET = 10 ;
538- constexpr size_t EOCD_CD_SIZE_OFFSET = 12 ;
539- constexpr size_t EOCD_CD_START_OFFSET = 16 ;
535+ constexpr size_t EOCD_TOTAL_ENTRIES_OFFSET = 10uz ;
536+ constexpr size_t EOCD_CD_SIZE_OFFSET = 12uz ;
537+ constexpr size_t EOCD_CD_START_OFFSET = 16uz ;
540538
541539 static_assert (BufSize >= ZIP_EOCD_LEN, " Buffer too short for EOCD" );
542540
@@ -627,12 +625,12 @@ EmbeddedAssemblies::zip_read_field (T const& buf, size_t index, size_t count, dy
627625bool
628626EmbeddedAssemblies::zip_read_entry_info (std::vector<uint8_t > const & buf, dynamic_local_string<SENSIBLE_PATH_MAX>& file_name, ZipEntryLoadState &state)
629627{
630- constexpr size_t CD_COMPRESSION_METHOD_OFFSET = 10 ;
631- constexpr size_t CD_UNCOMPRESSED_SIZE_OFFSET = 24 ;
632- constexpr size_t CD_FILENAME_LENGTH_OFFSET = 28 ;
633- constexpr size_t CD_EXTRA_LENGTH_OFFSET = 30 ;
634- constexpr size_t CD_LOCAL_HEADER_POS_OFFSET = 42 ;
635- constexpr size_t CD_COMMENT_LENGTH_OFFSET = 32 ;
628+ constexpr size_t CD_COMPRESSION_METHOD_OFFSET = 10uz ;
629+ constexpr size_t CD_UNCOMPRESSED_SIZE_OFFSET = 24uz ;
630+ constexpr size_t CD_FILENAME_LENGTH_OFFSET = 28uz ;
631+ constexpr size_t CD_EXTRA_LENGTH_OFFSET = 30uz ;
632+ constexpr size_t CD_LOCAL_HEADER_POS_OFFSET = 42uz ;
633+ constexpr size_t CD_COMMENT_LENGTH_OFFSET = 32uz ;
636634
637635 size_t index = state.buf_offset ;
638636 zip_ensure_valid_params (buf, index, ZIP_CENTRAL_LEN);
0 commit comments