From be1954e04cb5a0c3a526f78ed5490a5e65310280 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 15 Oct 2020 14:49:45 -0400 Subject: core: Fix clang build Recent changes to the build system that made more warnings be flagged as errors caused building via clang to break. Fixes #4795 --- src/core/loader/elf.cpp | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'src/core/loader') diff --git a/src/core/loader/elf.cpp b/src/core/loader/elf.cpp index dca1fcb18..86d0527fc 100644 --- a/src/core/loader/elf.cpp +++ b/src/core/loader/elf.cpp @@ -220,18 +220,19 @@ public: } const char* GetSectionName(int section) const; const u8* GetSectionDataPtr(int section) const { - if (section < 0 || section >= header->e_shnum) - return nullptr; - if (sections[section].sh_type != SHT_NOBITS) - return GetPtr(sections[section].sh_offset); - else + if (section < 0 || section >= header->e_shnum) { return nullptr; + } + if (sections[section].sh_type != SHT_NOBITS) { + return GetPtr(static_cast(sections[section].sh_offset)); + } + return nullptr; } bool IsCodeSection(int section) const { return sections[section].sh_type == SHT_PROGBITS; } const u8* GetSegmentPtr(int segment) { - return GetPtr(segments[segment].p_offset); + return GetPtr(static_cast(segments[segment].p_offset)); } u32 GetSectionAddr(SectionID section) const { return sectionAddrs[section]; @@ -258,14 +259,14 @@ ElfReader::ElfReader(void* ptr) { } const char* ElfReader::GetSectionName(int section) const { - if (sections[section].sh_type == SHT_NULL) + if (sections[section].sh_type == SHT_NULL) { return nullptr; + } - int name_offset = sections[section].sh_name; - const char* ptr = reinterpret_cast(GetSectionDataPtr(header->e_shstrndx)); - - if (ptr) + const auto name_offset = sections[section].sh_name; + if (const auto* ptr = reinterpret_cast(GetSectionDataPtr(header->e_shstrndx))) { return ptr + name_offset; + } return nullptr; } @@ -291,7 +292,7 @@ Kernel::CodeSet ElfReader::LoadInto(VAddr vaddr) { for (unsigned int i = 0; i < header->e_phnum; ++i) { const Elf32_Phdr* p = &segments[i]; if (p->p_type == PT_LOAD) { - total_image_size += (p->p_memsz + 0xFFF) & ~0xFFF; + total_image_size += (p->p_memsz + 0xFFF) & ~0xFFFU; } } @@ -300,14 +301,14 @@ Kernel::CodeSet ElfReader::LoadInto(VAddr vaddr) { Kernel::CodeSet codeset; - for (unsigned int i = 0; i < header->e_phnum; ++i) { + for (u32 i = 0; i < header->e_phnum; ++i) { const Elf32_Phdr* p = &segments[i]; LOG_DEBUG(Loader, "Type: {} Vaddr: {:08X} Filesz: {:08X} Memsz: {:08X} ", p->p_type, p->p_vaddr, p->p_filesz, p->p_memsz); if (p->p_type == PT_LOAD) { Kernel::CodeSet::Segment* codeset_segment; - u32 permission_flags = p->p_flags & (PF_R | PF_W | PF_X); + const u32 permission_flags = p->p_flags & (PF_R | PF_W | PF_X); if (permission_flags == (PF_R | PF_X)) { codeset_segment = &codeset.CodeSegment(); } else if (permission_flags == (PF_R)) { @@ -329,14 +330,14 @@ Kernel::CodeSet ElfReader::LoadInto(VAddr vaddr) { } const VAddr segment_addr = base_addr + p->p_vaddr; - const u32 aligned_size = (p->p_memsz + 0xFFF) & ~0xFFF; + const u32 aligned_size = (p->p_memsz + 0xFFF) & ~0xFFFU; codeset_segment->offset = current_image_position; codeset_segment->addr = segment_addr; codeset_segment->size = aligned_size; - std::memcpy(program_image.data() + current_image_position, GetSegmentPtr(i), - p->p_filesz); + std::memcpy(program_image.data() + current_image_position, + GetSegmentPtr(static_cast(i)), p->p_filesz); current_image_position += aligned_size; } } -- cgit v1.2.3