terminate read strings so that json parsing no longer fails
This commit is contained in:
parent
4a6989f5ea
commit
da05b706e4
2 changed files with 3 additions and 7 deletions
5
main.cpp
5
main.cpp
|
@ -21,11 +21,6 @@ using json = nlohmann::json;
|
|||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
auto sway = Sway();
|
||||
auto resp = sway.sendIPC(SWAY_GET_TREE);
|
||||
json rep = json::parse(resp.msg);
|
||||
auto rootRecord = SwayRecord(rep);
|
||||
|
||||
QApplication a(argc, argv);
|
||||
QCoreApplication::setOrganizationName("Grimmauld");
|
||||
QCoreApplication::setApplicationName("SwayMux");
|
||||
|
|
|
@ -59,13 +59,14 @@ struct swaymsg {
|
|||
>> Formatter::to_str);
|
||||
}
|
||||
|
||||
char msgBuff[payloadLen];
|
||||
char msgBuff[payloadLen + 1];
|
||||
if ((dlen = recv(sockfd, msgBuff, payloadLen, 0)) != payloadLen) {
|
||||
throw std::runtime_error(
|
||||
Formatter() << "Swaysock: Unexpected length on recv() call for message: " << dlen
|
||||
>> Formatter::to_str);
|
||||
}
|
||||
return swaymsg(payloadType, msgBuff, payloadLen);
|
||||
msgBuff[payloadLen] = '\00'; // make sure we have a c-style string that is properly terminated or json parsing gets all weird...
|
||||
return swaymsg(payloadType, msgBuff, payloadLen + 1);
|
||||
};
|
||||
|
||||
constexpr const static char *magic = "i3-ipc";
|
||||
|
|
Loading…
Reference in a new issue