Skip to content

Commit

Permalink
more error checking
Browse files Browse the repository at this point in the history
  • Loading branch information
sirf committed Feb 12, 2024
1 parent f7688b5 commit fd8e5ba
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/melt/jit.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ static JitControl *read_control() {
struct timeval timeout;
timeout.tv_sec = 1;
timeout.tv_usec = 0;
if (select(melt_sock_fd + 1, &set, NULL, NULL, &timeout) <= 0) {
if (melt_sock_fd < 0 || select(melt_sock_fd + 1, &set, NULL, NULL, &timeout) <= 0) {
return NULL;
}

Expand All @@ -102,7 +102,7 @@ static void write_status(JitStatus *const jit_status) {
static char *buf = NULL;
static int buf_len = 0;

if (melt_sock_fd < 0) {
if (melt_sock_fd < 0 || jit_sock_addr_len <= 0) {
return;
}

Expand All @@ -116,12 +116,10 @@ static void write_status(JitStatus *const jit_status) {
buf_len = len;
}

if (jit_sock_addr_len > 0) {
jit_status__pack(jit_status, buf);
if (sendto(melt_sock_fd, buf, len, 0, (struct sockaddr*) &jit_sock_addr, jit_sock_addr_len) != len) {
perror("sendto");
exit(1);
}
jit_status__pack(jit_status, buf);
if (sendto(melt_sock_fd, buf, len, 0, (struct sockaddr*) &jit_sock_addr, jit_sock_addr_len) != len) {
perror("sendto");
exit(1);
}
}

Expand Down

0 comments on commit fd8e5ba

Please sign in to comment.