summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Lioncash2018-10-24 15:25:30 -0400
committerGravatar Lioncash2018-10-24 18:22:24 -0400
commit6f00628564510e22eef1f3180d974a94b896c36a (patch)
tree6e6e37ba13b5e240691f2dbc382ec3c5e1582f5f
parentservice/acc: Early return in failure case in LoadImage() (diff)
downloadyuzu-6f00628564510e22eef1f3180d974a94b896c36a.tar.gz
yuzu-6f00628564510e22eef1f3180d974a94b896c36a.tar.xz
yuzu-6f00628564510e22eef1f3180d974a94b896c36a.zip
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.
Diffstat (limited to '')
-rw-r--r--src/core/hle/service/acc/acc.cpp13
1 files changed, 8 insertions, 5 deletions
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 @@
21 21
22namespace Service::Account { 22namespace Service::Account {
23 23
24constexpr u32 MAX_JPEG_IMAGE_SIZE = 0x20000;
25
26// TODO: RE this structure 24// TODO: RE this structure
27struct UserData { 25struct UserData {
28 INSERT_PADDING_WORDS(1); 26 INSERT_PADDING_WORDS(1);
@@ -39,6 +37,11 @@ static std::string GetImagePath(UUID uuid) {
39 "/system/save/8000000000000010/su/avators/" + uuid.FormatSwitch() + ".jpg"; 37 "/system/save/8000000000000010/su/avators/" + uuid.FormatSwitch() + ".jpg";
40} 38}
41 39
40static constexpr u32 SanitizeJPEGSize(std::size_t size) {
41 constexpr std::size_t max_jpeg_image_size = 0x20000;
42 return static_cast<u32>(std::min(size, max_jpeg_image_size));
43}
44
42class IProfile final : public ServiceFramework<IProfile> { 45class IProfile final : public ServiceFramework<IProfile> {
43public: 46public:
44 explicit IProfile(UUID user_id, ProfileManager& profile_manager) 47 explicit IProfile(UUID user_id, ProfileManager& profile_manager)
@@ -112,12 +115,12 @@ private:
112 return; 115 return;
113 } 116 }
114 117
115 const auto size = std::min<u32>(image.GetSize(), MAX_JPEG_IMAGE_SIZE); 118 const u32 size = SanitizeJPEGSize(image.GetSize());
116 std::vector<u8> buffer(size); 119 std::vector<u8> buffer(size);
117 image.ReadBytes(buffer.data(), buffer.size()); 120 image.ReadBytes(buffer.data(), buffer.size());
118 121
119 ctx.WriteBuffer(buffer.data(), buffer.size()); 122 ctx.WriteBuffer(buffer.data(), buffer.size());
120 rb.Push<u32>(buffer.size()); 123 rb.Push<u32>(size);
121 } 124 }
122 125
123 void GetImageSize(Kernel::HLERequestContext& ctx) { 126 void GetImageSize(Kernel::HLERequestContext& ctx) {
@@ -133,7 +136,7 @@ private:
133 "Failed to load user provided image! Falling back to built-in backup..."); 136 "Failed to load user provided image! Falling back to built-in backup...");
134 rb.Push<u32>(backup_jpeg_size); 137 rb.Push<u32>(backup_jpeg_size);
135 } else { 138 } else {
136 rb.Push<u32>(std::min<u32>(image.GetSize(), MAX_JPEG_IMAGE_SIZE)); 139 rb.Push<u32>(SanitizeJPEGSize(image.GetSize()));
137 } 140 }
138 } 141 }
139 142