Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/controller/inputoutputmode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,6 @@ void setIoStreamsToBinaryMode()

using namespace pcsc_cpp;

uint32_t readMessageLength(std::istream& input)
{
uint32_t messageLength = 0;
input.read(reinterpret_cast<char*>(&messageLength), sizeof(messageLength));
return messageLength;
}

void writeResponseLength(std::ostream& stream, const uint32_t responseLength)
{
stream.write(reinterpret_cast<const char*>(&responseLength), sizeof(responseLength));
Expand All @@ -70,7 +63,11 @@ CommandWithArguments readCommandFromStdin()
setIoStreamsToBinaryMode();
#endif

const auto messageLength = readMessageLength(std::cin);
uint32_t messageLength = 0;
std::cin.read(reinterpret_cast<char*>(&messageLength), sizeof(messageLength));
if (std::cin.gcount() != sizeof(messageLength) || !std::cin.good()) {
throw std::runtime_error("readCommandFromStdin: Failed to read message length from stdin");
}

if (messageLength < 5) {
throw std::invalid_argument("readCommandFromStdin: Message length is "
Expand All @@ -83,8 +80,11 @@ CommandWithArguments readCommandFromStdin()
+ " exceeds maximum allowed length 8192");
}

auto message = QByteArray(int(messageLength), '\0');
auto message = QByteArray(qsizetype(messageLength), '\0');
std::cin.read(message.data(), messageLength);
if (std::cin.gcount() != messageLength || !std::cin.good()) {
throw std::runtime_error("readCommandFromStdin: Failed to read the expected number of bytes from stdin");
}

const auto json = QJsonDocument::fromJson(message);

Expand Down
Loading