mirror of
https://github.com/tsl0922/ttyd.git
synced 2025-12-28 14:34:34 +01:00
protocol: fix -Wstringop-overflow compile warning
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user