Permalink
Browse files

Optimize code

Signed-off-by: Jianhui Zhao <jianhuizhao329@gmail.com>
  • Loading branch information...
zhaojh329 committed Dec 28, 2018
1 parent 59f1cf4 commit c266af2eda9ec390ae934a7e4b67692d287d7766
Showing with 3 additions and 8 deletions.
  1. +3 −8 src/command.c
@@ -147,21 +147,16 @@ static void cmd_err_reply(struct uwsc_client *ws, int id, int err)

static void cmd_reply(struct task *t, int code)
{
int stdoelen = buffer_length(&t->ob) + buffer_length(&t->eb);
int len = buffer_length(&t->ob) + buffer_length(&t->eb) + 100;
char *str;

if (stdoelen > 65000) {
cmd_err_reply(t->ws, t->id, RTTY_CMD_ERR_RESP_TOOBIG);
return;
}

str = malloc(stdoelen + 100);
str = malloc(len);
if (!str) {
cmd_err_reply(t->ws, t->id, RTTY_CMD_ERR_NOMEM);
return;
}

snprintf(str, stdoelen + 100 - 1, "{\"type\":\"cmd\",\"id\":%d,"
snprintf(str, len, "{\"type\":\"cmd\",\"id\":%d,"
"\"attrs\":{\"stdout\":\"%.*s\",\"stderr\":\"%.*s\",\"code\":%d}}", t->id,
(int)buffer_length(&t->ob), (char *)buffer_data(&t->ob),
(int)buffer_length(&t->eb), (char *)buffer_data(&t->eb),

0 comments on commit c266af2

Please sign in to comment.