diff --git a/kitty/boss.py b/kitty/boss.py index 54e6d738f..da1df54b2 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -516,11 +516,10 @@ class Boss: if window is not None and response is not None and not isinstance(response, AsyncResponse): window.send_cmd_response(response) if peer_id > 0: - if response is None or isinstance(response, AsyncResponse): - data = b'' - else: - data = encode_response_for_peer(response) - send_data_to_peer(peer_id, data) + if response is None: + send_data_to_peer(peer_id, b'') + elif not isinstance(response, AsyncResponse): + send_data_to_peer(peer_id, encode_response_for_peer(response)) def _execute_remote_command(self, pcmd: Dict[str, Any], window: Optional[Window] = None, peer_id: int = 0) -> RCResponse: from .remote_control import handle_cmd diff --git a/kitty/child-monitor.c b/kitty/child-monitor.c index 8c974cb7f..8f28f738f 100644 --- a/kitty/child-monitor.c +++ b/kitty/child-monitor.c @@ -442,7 +442,7 @@ parse_input(ChildMonitor *self) { } if (resp) { if (PyBytes_Check(resp)) send_response_to_peer(msg->peer_id, PyBytes_AS_STRING(resp), PyBytes_GET_SIZE(resp)); - else if (resp == Py_None || resp == Py_True) send_response_to_peer(msg->peer_id, NULL, 0); + else if (resp == Py_None) send_response_to_peer(msg->peer_id, NULL, 0); Py_CLEAR(resp); } else send_response_to_peer(msg->peer_id, NULL, 0); } @@ -1732,8 +1732,10 @@ send_response_to_peer(id_type peer_id, const char *msg, size_t msg_sz) { peer->write.capacity += msg_sz; } else fatal("Out of memory"); } - if (msg) memcpy(peer->write.data + peer->write.used, msg, msg_sz); - peer->write.used += msg_sz; + if (msg_sz && msg) { + memcpy(peer->write.data + peer->write.used, msg, msg_sz); + peer->write.used += msg_sz; + } } wakeup = true; break;