From 6f00628564510e22eef1f3180d974a94b896c36a Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 24 Oct 2018 15:25:30 -0400 Subject: service/acc: Silence compiler warnings Silences compiler warnings related to truncation. This also introduces a small helper function to perform the clamping of the image size. --- src/core/hle/service/acc/acc.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/core/hle/service/acc/acc.cpp b/src/core/hle/service/acc/acc.cpp index 17e3aa0e2..d17d784cf 100644 --- a/src/core/hle/service/acc/acc.cpp +++ b/src/core/hle/service/acc/acc.cpp @@ -21,8 +21,6 @@ namespace Service::Account { -constexpr u32 MAX_JPEG_IMAGE_SIZE = 0x20000; - // TODO: RE this structure struct UserData { INSERT_PADDING_WORDS(1); @@ -39,6 +37,11 @@ static std::string GetImagePath(UUID uuid) { "/system/save/8000000000000010/su/avators/" + uuid.FormatSwitch() + ".jpg"; } +static constexpr u32 SanitizeJPEGSize(std::size_t size) { + constexpr std::size_t max_jpeg_image_size = 0x20000; + return static_cast(std::min(size, max_jpeg_image_size)); +} + class IProfile final : public ServiceFramework { public: explicit IProfile(UUID user_id, ProfileManager& profile_manager) @@ -112,12 +115,12 @@ private: return; } - const auto size = std::min(image.GetSize(), MAX_JPEG_IMAGE_SIZE); + const u32 size = SanitizeJPEGSize(image.GetSize()); std::vector buffer(size); image.ReadBytes(buffer.data(), buffer.size()); ctx.WriteBuffer(buffer.data(), buffer.size()); - rb.Push(buffer.size()); + rb.Push(size); } void GetImageSize(Kernel::HLERequestContext& ctx) { @@ -133,7 +136,7 @@ private: "Failed to load user provided image! Falling back to built-in backup..."); rb.Push(backup_jpeg_size); } else { - rb.Push(std::min(image.GetSize(), MAX_JPEG_IMAGE_SIZE)); + rb.Push(SanitizeJPEGSize(image.GetSize())); } } -- cgit v1.2.3