From c9ead205a4cbf5021b34b12a713cd8014334b848 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Wed, 1 Jul 2020 09:22:09 -0700 Subject: [PATCH] libstrat: fix bugs/compiler warnings --- libraries/config/common.mk | 2 +- libraries/libstratosphere/Makefile | 2 +- .../fs/impl/fs_priority_utils.hpp | 16 ++++++------ .../erpt/srv/erpt_srv_journal_for_reports.cpp | 2 +- .../source/erpt/srv/erpt_srv_stream.cpp | 1 + .../source/fs/fs_access_log.cpp | 25 ++++++++++++------- .../libstratosphere/source/fs/fs_priority.cpp | 2 +- ...system_alignment_matching_storage_impl.cpp | 2 ++ 8 files changed, 31 insertions(+), 21 deletions(-) diff --git a/libraries/config/common.mk b/libraries/config/common.mk index 8973da718..6c5516238 100644 --- a/libraries/config/common.mk +++ b/libraries/config/common.mk @@ -19,7 +19,7 @@ export ATMOSPHERE_DEFINES := -DATMOSPHERE export ATMOSPHERE_SETTINGS := -fPIE -g export ATMOSPHERE_CFLAGS := -Wall -ffunction-sections -fdata-sections -fno-strict-aliasing -fwrapv \ -fno-asynchronous-unwind-tables -fno-unwind-tables -fno-stack-protector \ - -Wno-format-truncation -Wno-format-zero-length + -Wno-format-truncation -Wno-format-zero-length -Wno-stringop-truncation export ATMOSPHERE_CXXFLAGS := -fno-rtti -fno-exceptions -std=gnu++20 export ATMOSPHERE_ASFLAGS := diff --git a/libraries/libstratosphere/Makefile b/libraries/libstratosphere/Makefile index 287bed57d..29de3a2a6 100644 --- a/libraries/libstratosphere/Makefile +++ b/libraries/libstratosphere/Makefile @@ -116,7 +116,7 @@ dist: dist-src dist-bin #--------------------------------------------------------------------------------- clean: @echo clean ... - @rm -fr release lib *.bz2 + @rm -fr release lib *.bz2 include/stratosphere.hpp.gch #--------------------------------------------------------------------------------- else diff --git a/libraries/libstratosphere/include/stratosphere/fs/impl/fs_priority_utils.hpp b/libraries/libstratosphere/include/stratosphere/fs/impl/fs_priority_utils.hpp index 84d15b5f6..043483df8 100644 --- a/libraries/libstratosphere/include/stratosphere/fs/impl/fs_priority_utils.hpp +++ b/libraries/libstratosphere/include/stratosphere/fs/impl/fs_priority_utils.hpp @@ -37,10 +37,10 @@ namespace ams::fs::impl { AMS_ASSERT(out != nullptr); switch (priority) { - case PriorityRaw_Normal: *out = TlsIoPriority_Normal; - case PriorityRaw_Realtime: *out = TlsIoPriority_Realtime; - case PriorityRaw_Low: *out = TlsIoPriority_Low; - case PriorityRaw_Background: *out = TlsIoPriority_Background; + case PriorityRaw_Normal: *out = TlsIoPriority_Normal; break; + case PriorityRaw_Realtime: *out = TlsIoPriority_Realtime; break; + case PriorityRaw_Low: *out = TlsIoPriority_Low; break; + case PriorityRaw_Background: *out = TlsIoPriority_Background; break; default: return fs::ResultInvalidArgument(); } @@ -51,10 +51,10 @@ namespace ams::fs::impl { AMS_ASSERT(out != nullptr); switch (static_cast(tls_io)) { - case TlsIoPriority_Normal: *out = PriorityRaw_Normal; - case TlsIoPriority_Realtime: *out = PriorityRaw_Realtime; - case TlsIoPriority_Low: *out = PriorityRaw_Low; - case TlsIoPriority_Background: *out = PriorityRaw_Background; + case TlsIoPriority_Normal: *out = PriorityRaw_Normal; break; + case TlsIoPriority_Realtime: *out = PriorityRaw_Realtime; break; + case TlsIoPriority_Low: *out = PriorityRaw_Low; break; + case TlsIoPriority_Background: *out = PriorityRaw_Background; break; default: return fs::ResultInvalidArgument(); } diff --git a/libraries/libstratosphere/source/erpt/srv/erpt_srv_journal_for_reports.cpp b/libraries/libstratosphere/source/erpt/srv/erpt_srv_journal_for_reports.cpp index 5db553eb2..f32c4f10f 100644 --- a/libraries/libstratosphere/source/erpt/srv/erpt_srv_journal_for_reports.cpp +++ b/libraries/libstratosphere/source/erpt/srv/erpt_srv_journal_for_reports.cpp @@ -98,7 +98,7 @@ namespace ams::erpt::srv { } s64 JournalForReports::GetMaxReportSize() { - s64 max_size; + s64 max_size = 0; for (auto it = s_record_list.begin(); it != s_record_list.end(); it++) { max_size = std::max(max_size, it->info.report_size); } diff --git a/libraries/libstratosphere/source/erpt/srv/erpt_srv_stream.cpp b/libraries/libstratosphere/source/erpt/srv/erpt_srv_stream.cpp index e67f0b623..83c6879d5 100644 --- a/libraries/libstratosphere/source/erpt/srv/erpt_srv_stream.cpp +++ b/libraries/libstratosphere/source/erpt/srv/erpt_srv_stream.cpp @@ -75,6 +75,7 @@ namespace ams::erpt::srv { auto file_guard = SCOPE_GUARD { if (mode == StreamMode_Write) { fs::CloseFile(this->file_handle); } }; std::strncpy(this->file_name, path, sizeof(this->file_name)); + this->file_name[sizeof(this->file_name) - 1] = '\x00'; this->buffer = reinterpret_cast(Allocate(buffer_size)); R_UNLESS(this->buffer != nullptr, erpt::ResultOutOfMemory()); diff --git a/libraries/libstratosphere/source/fs/fs_access_log.cpp b/libraries/libstratosphere/source/fs/fs_access_log.cpp index 9a0524a0a..7f06278a6 100644 --- a/libraries/libstratosphere/source/fs/fs_access_log.cpp +++ b/libraries/libstratosphere/source/fs/fs_access_log.cpp @@ -183,8 +183,8 @@ namespace ams::fs::impl { return g_access_log_manager_printer_callback_manager; } - const char *GetPriorityRawName() { - return fs::impl::IdString().ToString(fs::GetPriorityRawOnCurrentThreadInternal()); + const char *GetPriorityRawName(fs::impl::IdString &id_string) { + return id_string.ToString(fs::GetPriorityRawOnCurrentThreadInternal()); } Result OutputAccessLogToSdCardImpl(const char *log, size_t size) { @@ -405,28 +405,32 @@ namespace ams::fs::impl { void OutputAccessLog(Result result, os::Tick start, os::Tick end, const char *name, fs::FileHandle handle, const char *fmt, ...) { std::va_list vl; va_start(vl, fmt); - OutputAccessLog(result, GetPriorityRawName(), start, end, name, handle.handle, fmt, vl); + fs::impl::IdString id_string; + OutputAccessLog(result, GetPriorityRawName(id_string), start, end, name, handle.handle, fmt, vl); va_end(vl); } void OutputAccessLog(Result result, os::Tick start, os::Tick end, const char *name, fs::DirectoryHandle handle, const char *fmt, ...) { std::va_list vl; va_start(vl, fmt); - OutputAccessLog(result, GetPriorityRawName(), start, end, name, handle.handle, fmt, vl); + fs::impl::IdString id_string; + OutputAccessLog(result, GetPriorityRawName(id_string), start, end, name, handle.handle, fmt, vl); va_end(vl); } void OutputAccessLog(Result result, os::Tick start, os::Tick end, const char *name, fs::impl::IdentifyAccessLogHandle handle, const char *fmt, ...) { std::va_list vl; va_start(vl, fmt); - OutputAccessLog(result, GetPriorityRawName(), start, end, name, handle.handle, fmt, vl); + fs::impl::IdString id_string; + OutputAccessLog(result, GetPriorityRawName(id_string), start, end, name, handle.handle, fmt, vl); va_end(vl); } void OutputAccessLog(Result result, os::Tick start, os::Tick end, const char *name, const void *handle, const char *fmt, ...) { std::va_list vl; va_start(vl, fmt); - OutputAccessLog(result, GetPriorityRawName(), start, end, name, handle, fmt, vl); + fs::impl::IdString id_string; + OutputAccessLog(result, GetPriorityRawName(id_string), start, end, name, handle, fmt, vl); va_end(vl); } @@ -441,7 +445,8 @@ namespace ams::fs::impl { if (R_FAILED(result)) { std::va_list vl; va_start(vl, fmt); - OutputAccessLog(result, GetPriorityRawName(), start, end, name, handle.handle, fmt, vl); + fs::impl::IdString id_string; + OutputAccessLog(result, GetPriorityRawName(id_string), start, end, name, handle.handle, fmt, vl); va_end(vl); } } @@ -450,7 +455,8 @@ namespace ams::fs::impl { if (R_FAILED(result)) { std::va_list vl; va_start(vl, fmt); - OutputAccessLog(result, GetPriorityRawName(), start, end, name, handle.handle, fmt, vl); + fs::impl::IdString id_string; + OutputAccessLog(result, GetPriorityRawName(id_string), start, end, name, handle.handle, fmt, vl); va_end(vl); } } @@ -459,7 +465,8 @@ namespace ams::fs::impl { if (R_FAILED(result)) { std::va_list vl; va_start(vl, fmt); - OutputAccessLog(result, GetPriorityRawName(), start, end, name, handle, fmt, vl); + fs::impl::IdString id_string; + OutputAccessLog(result, GetPriorityRawName(id_string), start, end, name, handle, fmt, vl); va_end(vl); } } diff --git a/libraries/libstratosphere/source/fs/fs_priority.cpp b/libraries/libstratosphere/source/fs/fs_priority.cpp index 3f3686262..8c23df02a 100644 --- a/libraries/libstratosphere/source/fs/fs_priority.cpp +++ b/libraries/libstratosphere/source/fs/fs_priority.cpp @@ -130,7 +130,7 @@ namespace ams::fs { PriorityRaw GetPriorityRawOnCurrentThreadInternal() { fs::PriorityRaw priority_raw; - AMS_FS_R_ABORT_UNLESS(GetPriorityRawImpl(std::addressof(priority_raw), os::GetCurrentThread())); + R_ABORT_UNLESS(GetPriorityRawImpl(std::addressof(priority_raw), os::GetCurrentThread())); return priority_raw; } diff --git a/libraries/libstratosphere/source/fssystem/fssystem_alignment_matching_storage_impl.cpp b/libraries/libstratosphere/source/fssystem/fssystem_alignment_matching_storage_impl.cpp index 225a9656d..920e8a2e8 100644 --- a/libraries/libstratosphere/source/fssystem/fssystem_alignment_matching_storage_impl.cpp +++ b/libraries/libstratosphere/source/fssystem/fssystem_alignment_matching_storage_impl.cpp @@ -73,6 +73,8 @@ namespace ams::fssystem { core_size = (size < buffer_round_up_difference) ? 0 : util::AlignDown(size - buffer_round_up_difference, data_alignment); buffer_gap = buffer_round_up_difference; offset_gap = GetRoundDownDifference(offset, data_alignment); + + covered_offset = offset; } /* Read the core portion. */