From f85bde3ca38587e7022fca1c65749a7bc7dfa0d8 Mon Sep 17 00:00:00 2001 From: Pengfei Date: Wed, 14 Jul 2021 17:01:14 +0800 Subject: [PATCH] Replace `&vec[0]` with `vec.data()` When the vector is empty, using `&vec[0]` involves undefined behaviour. While that works fine most of the time, Flatpak builds aborted on a failed `__builtin_expect`. I searched for such occurences across the codebase with the regex `(?(file.GetSize())); - return file.ReadArray(&str[0], str.size()); + return file.ReadArray(str.data(), str.size()); } void SplitFilename83(const std::string& filename, std::array& short_name, diff --git a/src/core/file_sys/ncch_container.cpp b/src/core/file_sys/ncch_container.cpp index 831c930fc..78bcda734 100644 --- a/src/core/file_sys/ncch_container.cpp +++ b/src/core/file_sys/ncch_container.cpp @@ -554,15 +554,16 @@ Loader::ResultStatus NCCHContainer::LoadSectionExeFS(const char* name, std::vect // Decompress .code section... u32 decompressed_size = LZSS_GetDecompressedSize(&temp_buffer[0], section.size); buffer.resize(decompressed_size); - if (!LZSS_Decompress(&temp_buffer[0], section.size, &buffer[0], decompressed_size)) + if (!LZSS_Decompress(&temp_buffer[0], section.size, buffer.data(), + decompressed_size)) return Loader::ResultStatus::ErrorInvalidFormat; } else { // Section is uncompressed... buffer.resize(section.size); - if (exefs_file.ReadBytes(&buffer[0], section.size) != section.size) + if (exefs_file.ReadBytes(buffer.data(), section.size) != section.size) return Loader::ResultStatus::Error; if (is_encrypted) { - dec.ProcessData(&buffer[0], &buffer[0], section.size); + dec.ProcessData(buffer.data(), buffer.data(), section.size); } } @@ -641,7 +642,7 @@ Loader::ResultStatus NCCHContainer::LoadOverrideExeFSSection(const char* name, buffer.resize(section_size); section_file.Seek(0, SEEK_SET); - if (section_file.ReadBytes(&buffer[0], section_size) == section_size) { + if (section_file.ReadBytes(buffer.data(), section_size) == section_size) { LOG_WARNING(Service_FS, "File {} overriding built-in ExeFS file", path); return Loader::ResultStatus::Success; } diff --git a/src/core/loader/3dsx.cpp b/src/core/loader/3dsx.cpp index 95ef0f1ed..d9cba3b16 100644 --- a/src/core/loader/3dsx.cpp +++ b/src/core/loader/3dsx.cpp @@ -342,7 +342,7 @@ ResultStatus AppLoader_THREEDSX::ReadIcon(std::vector& buffer) { file.Seek(hdr.smdh_offset, SEEK_SET); buffer.resize(hdr.smdh_size); - if (file.ReadBytes(&buffer[0], hdr.smdh_size) != hdr.smdh_size) + if (file.ReadBytes(buffer.data(), hdr.smdh_size) != hdr.smdh_size) return ResultStatus::Error; return ResultStatus::Success;