diff --git a/troposphere/haze/include/haze/common.hpp b/troposphere/haze/include/haze/common.hpp index ccab145ce..d4d412d6d 100644 --- a/troposphere/haze/include/haze/common.hpp +++ b/troposphere/haze/include/haze/common.hpp @@ -16,7 +16,6 @@ #pragma once #include -#include #include #include #include diff --git a/troposphere/haze/include/haze/ptp_data_builder.hpp b/troposphere/haze/include/haze/ptp_data_builder.hpp index 2e9d8dceb..da7c51dfe 100644 --- a/troposphere/haze/include/haze/ptp_data_builder.hpp +++ b/troposphere/haze/include/haze/ptp_data_builder.hpp @@ -88,9 +88,11 @@ namespace haze { template Result Add(T value) { - const auto bytes = std::bit_cast>(value); + u8 bytes[sizeof(T)]; - R_RETURN(this->AddBuffer(bytes.data(), bytes.size())); + std::memcpy(bytes, std::addressof(value), sizeof(T)); + + R_RETURN(this->AddBuffer(bytes, sizeof(T))); } Result AddDataHeader(PtpUsbBulkContainer &request, u32 data_size) { diff --git a/troposphere/haze/include/haze/ptp_data_parser.hpp b/troposphere/haze/include/haze/ptp_data_parser.hpp index d862cc785..a30d5dc1f 100644 --- a/troposphere/haze/include/haze/ptp_data_parser.hpp +++ b/troposphere/haze/include/haze/ptp_data_parser.hpp @@ -75,13 +75,13 @@ namespace haze { } template - Result Read(T &out_t) { + Result Read(T *out_t) { size_t read_count; - std::array bytes = {}; + u8 bytes[sizeof(T)]; - R_TRY(this->ReadBuffer(bytes.data(), bytes.size(), std::addressof(read_count))); + R_TRY(this->ReadBuffer(bytes, sizeof(T), std::addressof(read_count))); - out_t = std::bit_cast(bytes); + std::memcpy(out_t, bytes, sizeof(T)); R_SUCCEED(); } @@ -90,12 +90,12 @@ namespace haze { /* The result will be null-terminated on successful completion. */ Result ReadString(char *out_string) { u8 len; - R_TRY(this->Read(len)); + R_TRY(this->Read(std::addressof(len))); /* Read characters one by one. */ for (size_t i = 0; i < len; i++) { u16 chr; - R_TRY(this->Read(chr)); + R_TRY(this->Read(std::addressof(chr))); *out_string++ = static_cast(chr); } diff --git a/troposphere/haze/source/ptp_responder.cpp b/troposphere/haze/source/ptp_responder.cpp index 4f517d887..8cf8d0999 100644 --- a/troposphere/haze/source/ptp_responder.cpp +++ b/troposphere/haze/source/ptp_responder.cpp @@ -200,7 +200,7 @@ namespace haze { Result PtpResponder::HandleRequestImpl() { PtpDataParser dp(s_bulk_read_buffer, std::addressof(m_usb_server)); - R_TRY(dp.Read(m_request_header)); + R_TRY(dp.Read(std::addressof(m_request_header))); switch (m_request_header.type) { case PtpUsbBulkContainerType_Command: R_RETURN(this->HandleCommandRequest(dp)); @@ -315,7 +315,7 @@ namespace haze { /* Get the storage ID the client requested information for. */ u32 storage_id; - R_TRY(dp.Read(storage_id)); + R_TRY(dp.Read(std::addressof(storage_id))); R_TRY(dp.Finalize()); /* Get the info from fs. */ @@ -359,9 +359,9 @@ namespace haze { /* Get the object ID the client requested enumeration for. */ u32 storage_id, object_format_code, association_object_handle; - R_TRY(dp.Read(storage_id)); - R_TRY(dp.Read(object_format_code)); - R_TRY(dp.Read(association_object_handle)); + R_TRY(dp.Read(std::addressof(storage_id))); + R_TRY(dp.Read(std::addressof(object_format_code))); + R_TRY(dp.Read(std::addressof(association_object_handle))); R_TRY(dp.Finalize()); /* Handle top-level requests. */ @@ -423,7 +423,7 @@ namespace haze { /* Get the object ID the client requested info for. */ u32 object_id; - R_TRY(dp.Read(object_id)); + R_TRY(dp.Read(std::addressof(object_id))); R_TRY(dp.Finalize()); /* Check if we know about the object. If we don't, it's an error. */ @@ -500,7 +500,7 @@ namespace haze { /* Get the object ID the client requested. */ u32 object_id; - R_TRY(dp.Read(object_id)); + R_TRY(dp.Read(std::addressof(object_id))); R_TRY(dp.Finalize()); /* Check if we know about the object. If we don't, it's an error. */ @@ -544,8 +544,8 @@ namespace haze { Result PtpResponder::SendObjectInfo(PtpDataParser &rdp) { u32 storage_id, parent_object; - R_TRY(rdp.Read(storage_id)); - R_TRY(rdp.Read(parent_object)); + R_TRY(rdp.Read(std::addressof(storage_id))); + R_TRY(rdp.Read(std::addressof(parent_object))); R_TRY(rdp.Finalize()); PtpDataParser dp(s_bulk_read_buffer, std::addressof(m_usb_server)); @@ -553,27 +553,27 @@ namespace haze { /* Ensure that we have a data header. */ PtpUsbBulkContainer data_header; - R_TRY(dp.Read(data_header)); + R_TRY(dp.Read(std::addressof(data_header))); R_UNLESS(data_header.type == PtpUsbBulkContainerType_Data, haze::ResultUnknownRequestType()); R_UNLESS(data_header.code == m_request_header.code, haze::ResultOperationNotSupported()); R_UNLESS(data_header.trans_id == m_request_header.trans_id, haze::ResultOperationNotSupported()); /* Read in the object info. */ - R_TRY(dp.Read(info.storage_id)); - R_TRY(dp.Read(info.object_format)); - R_TRY(dp.Read(info.protection_status)); - R_TRY(dp.Read(info.object_compressed_size)); - R_TRY(dp.Read(info.thumb_format)); - R_TRY(dp.Read(info.thumb_compressed_size)); - R_TRY(dp.Read(info.thumb_width)); - R_TRY(dp.Read(info.thumb_height)); - R_TRY(dp.Read(info.image_width)); - R_TRY(dp.Read(info.image_height)); - R_TRY(dp.Read(info.image_depth)); - R_TRY(dp.Read(info.parent_object)); - R_TRY(dp.Read(info.association_type)); - R_TRY(dp.Read(info.association_desc)); - R_TRY(dp.Read(info.sequence_number)); + R_TRY(dp.Read(std::addressof(info.storage_id))); + R_TRY(dp.Read(std::addressof(info.object_format))); + R_TRY(dp.Read(std::addressof(info.protection_status))); + R_TRY(dp.Read(std::addressof(info.object_compressed_size))); + R_TRY(dp.Read(std::addressof(info.thumb_format))); + R_TRY(dp.Read(std::addressof(info.thumb_compressed_size))); + R_TRY(dp.Read(std::addressof(info.thumb_width))); + R_TRY(dp.Read(std::addressof(info.thumb_height))); + R_TRY(dp.Read(std::addressof(info.image_width))); + R_TRY(dp.Read(std::addressof(info.image_height))); + R_TRY(dp.Read(std::addressof(info.image_depth))); + R_TRY(dp.Read(std::addressof(info.parent_object))); + R_TRY(dp.Read(std::addressof(info.association_type))); + R_TRY(dp.Read(std::addressof(info.association_desc))); + R_TRY(dp.Read(std::addressof(info.sequence_number))); R_TRY(dp.ReadString(s_filename_str)); R_TRY(dp.ReadString(s_capture_date_str)); R_TRY(dp.ReadString(s_modification_date_str)); @@ -626,7 +626,7 @@ namespace haze { /* Ensure that we have a data header. */ PtpUsbBulkContainer data_header; - R_TRY(dp.Read(data_header)); + R_TRY(dp.Read(std::addressof(data_header))); R_UNLESS(data_header.type == PtpUsbBulkContainerType_Data, haze::ResultUnknownRequestType()); R_UNLESS(data_header.code == m_request_header.code, haze::ResultOperationNotSupported()); R_UNLESS(data_header.trans_id == m_request_header.trans_id, haze::ResultOperationNotSupported()); @@ -671,7 +671,7 @@ namespace haze { Result PtpResponder::DeleteObject(PtpDataParser &dp) { u32 object_id; - R_TRY(dp.Read(object_id)); + R_TRY(dp.Read(std::addressof(object_id))); R_TRY(dp.Finalize()); /* Check if we know about the object. If we don't, it's an error. */