forked from eden-emu/eden
		
	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.
This commit is contained in:
		
							parent
							
								
									8eec717cce
								
							
						
					
					
						commit
						6da246b0c2
					
				
					 1 changed files with 8 additions and 5 deletions
				
			
		|  | @ -21,8 +21,6 @@ | ||||||
| 
 | 
 | ||||||
| namespace Service::Account { | namespace Service::Account { | ||||||
| 
 | 
 | ||||||
| constexpr u32 MAX_JPEG_IMAGE_SIZE = 0x20000; |  | ||||||
| 
 |  | ||||||
| // TODO: RE this structure
 | // TODO: RE this structure
 | ||||||
| struct UserData { | struct UserData { | ||||||
|     INSERT_PADDING_WORDS(1); |     INSERT_PADDING_WORDS(1); | ||||||
|  | @ -39,6 +37,11 @@ static std::string GetImagePath(UUID uuid) { | ||||||
|            "/system/save/8000000000000010/su/avators/" + uuid.FormatSwitch() + ".jpg"; |            "/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<u32>(std::min(size, max_jpeg_image_size)); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| class IProfile final : public ServiceFramework<IProfile> { | class IProfile final : public ServiceFramework<IProfile> { | ||||||
| public: | public: | ||||||
|     explicit IProfile(UUID user_id, ProfileManager& profile_manager) |     explicit IProfile(UUID user_id, ProfileManager& profile_manager) | ||||||
|  | @ -112,12 +115,12 @@ private: | ||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         const auto size = std::min<u32>(image.GetSize(), MAX_JPEG_IMAGE_SIZE); |         const u32 size = SanitizeJPEGSize(image.GetSize()); | ||||||
|         std::vector<u8> buffer(size); |         std::vector<u8> buffer(size); | ||||||
|         image.ReadBytes(buffer.data(), buffer.size()); |         image.ReadBytes(buffer.data(), buffer.size()); | ||||||
| 
 | 
 | ||||||
|         ctx.WriteBuffer(buffer.data(), buffer.size()); |         ctx.WriteBuffer(buffer.data(), buffer.size()); | ||||||
|         rb.Push<u32>(buffer.size()); |         rb.Push<u32>(size); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     void GetImageSize(Kernel::HLERequestContext& ctx) { |     void GetImageSize(Kernel::HLERequestContext& ctx) { | ||||||
|  | @ -133,7 +136,7 @@ private: | ||||||
|                         "Failed to load user provided image! Falling back to built-in backup..."); |                         "Failed to load user provided image! Falling back to built-in backup..."); | ||||||
|             rb.Push<u32>(backup_jpeg_size); |             rb.Push<u32>(backup_jpeg_size); | ||||||
|         } else { |         } else { | ||||||
|             rb.Push<u32>(std::min<u32>(image.GetSize(), MAX_JPEG_IMAGE_SIZE)); |             rb.Push<u32>(SanitizeJPEGSize(image.GetSize())); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Lioncash
						Lioncash