Skip to content

Commit

Permalink
protocol: fix -Wstringop-overflow compile warning
Browse files Browse the repository at this point in the history
  • Loading branch information
tsl0922 committed Mar 14, 2021
1 parent c0bdd7b commit 2480810
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
12 changes: 7 additions & 5 deletions src/protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,16 @@ static bool spawn_process(struct pss_tty *pss, uint16_t columns, uint16_t rows)

static void wsi_output(struct lws *wsi, pty_buf_t *buf) {
if (buf == NULL) return;
char *wbuf = xmalloc(LWS_PRE + 1 + buf->len);
memcpy(wbuf + LWS_PRE + 1, buf->base, buf->len);
wbuf[LWS_PRE] = OUTPUT;
char message[LWS_PRE + 1 + buf->len];
char *ptr= &message[LWS_PRE];

*ptr = OUTPUT;
memcpy(ptr + 1, buf->base, buf->len);
size_t n = buf->len + 1;
if (lws_write(wsi, (unsigned char *) wbuf + LWS_PRE, n, LWS_WRITE_BINARY) < n) {

if (lws_write(wsi, (unsigned char *) ptr, n, LWS_WRITE_BINARY) < n) {
lwsl_err("write OUTPUT to WS\n");
}
free(wbuf);
}

int callback_tty(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in,
Expand Down
4 changes: 2 additions & 2 deletions src/pty.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ static void close_cb(uv_handle_t *handle) {
free(handle);
}

pty_buf_t *pty_buf_init(char *base, ssize_t len) {
pty_buf_t *pty_buf_init(char *base, size_t len) {
pty_buf_t *buf = xmalloc(sizeof(pty_buf_t));
buf->base = xmalloc(len);
memcpy(buf->base, base, len);
Expand All @@ -58,7 +58,7 @@ static void read_cb(uv_stream_t *stream, ssize_t n, const uv_buf_t *buf) {
io->read_cb(io->ctx, NULL, true);
goto done;
}
io->read_cb(io->ctx, pty_buf_init(buf->base, n), false);
io->read_cb(io->ctx, pty_buf_init(buf->base, (size_t) n), false);

done:
free(buf->base);
Expand Down
4 changes: 2 additions & 2 deletions src/pty.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ bool conpty_init();

typedef struct {
char *base;
ssize_t len;
size_t len;
} pty_buf_t;

typedef void (*pty_read_cb)(void *, pty_buf_t *, bool);
Expand Down Expand Up @@ -58,7 +58,7 @@ struct pty_process_ {
void *ctx;
};

pty_buf_t *pty_buf_init(char *base, ssize_t len);
pty_buf_t *pty_buf_init(char *base, size_t len);
void pty_buf_free(pty_buf_t *buf);
pty_process *process_init(void *ctx, uv_loop_t *loop, char **argv);
bool process_running(pty_process *process);
Expand Down

0 comments on commit 2480810

Please sign in to comment.