Repository: skyline-emu/skyline
File: app/src/main/cpp/skyline/services/account/IProfile.cpp (C++)

Code before:
            u64 lastEditTimestamp;             //!< A POSIX UTC timestamp denoting the last account edit
            std::array<char, 0x20> nickname;   //!< UTF-8 Nickname
        } accountProfileBase = {
            .uid = userId,
        };

        size_t usernameSize{std::min(accountProfileBase.nickname.size() - 1, (*state.settings->usernameValue).size())};
        std::memcpy(accountProfileBase.nickname.data(), (*state.settings->usernameValue).c_str(), usernameSize);

        response.Push(accountProfileBase);

        return {};
    }

    Result IProfile::GetImageSize(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
        std::shared_ptr<vfs::Backing> profileImageIcon{GetProfilePicture()};
        response.Push<u32>(profileImageIcon->size);

        return {};
    }

    Result IProfile::LoadImage(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
        std::shared_ptr<vfs::Backing> profileImageIcon{GetProfilePicture()};
        std::vector<char> profileImage(profileImageIcon->size);

        profileImageIcon->Read(skyline::span<char>(profileImage), 0);

        request.outputBuf.at(0).copy_from(profileImage);
        response.Push<u32>(profileImageIcon->size);

        return {};
    }

    std::shared_ptr<vfs::Backing> IProfile::GetProfilePicture(){
        const std::string profilePicturePath{*state.settings->profilePictureValue};
        int fd{open((profilePicturePath).c_str(), O_RDONLY)};
        if (fd < 0)
            return state.os->assetFileSystem->OpenFile("skyline-logo.jpeg");
        else
            return std::make_shared<vfs::OsBacking>(fd, true);
    }
}


Review comment (suggestion):
```suggestion
        profileImageIcon->Read(span<char>(profileImage), 0);
```

Code after:
            std::array<char, 0x20> nickname;   //!< UTF-8 Nickname
        } accountProfileBase = {
            .uid = userId,
        };

        size_t usernameSize{std::min(accountProfileBase.nickname.size() - 1, (*state.settings->usernameValue).size())};
        std::memcpy(accountProfileBase.nickname.data(), (*state.settings->usernameValue).c_str(), usernameSize);

        response.Push(accountProfileBase);

        return {};
    }

    Result IProfile::GetImageSize(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
        std::shared_ptr<vfs::Backing> profileImageIcon{GetProfilePicture()};
        response.Push(static_cast<u32>(profileImageIcon->size));

        return {};
    }

    Result IProfile::LoadImage(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
        std::shared_ptr<vfs::Backing> profileImageIcon{GetProfilePicture()};

        profileImageIcon->Read(span(request.outputBuf.at(0)).first(profileImageIcon->size), 0);
        response.Push(static_cast<u32>(profileImageIcon->size));

        return {};
    }

    std::shared_ptr<vfs::Backing> IProfile::GetProfilePicture() {
        std::string profilePicturePath{*state.settings->profilePictureValue};
        int fd{open((profilePicturePath).c_str(), O_RDONLY)};
        if (fd < 0)
            // If we can't find the profile picture then just return the placeholder profile picture
            return state.os->assetFileSystem->OpenFile("profile_picture.jpeg");
        else
            return std::make_shared<vfs::OsBacking>(fd, true);
    }
}