diff --git a/client/tarantool/tc_buf.c b/client/tarantool/tc_buf.c index 9af10b3a8f1228c67efdc0d332889e20621fcf9c..4826ed1361294867c03afb24155875d829d138a5 100644 --- a/client/tarantool/tc_buf.c +++ b/client/tarantool/tc_buf.c @@ -37,9 +37,10 @@ /* Strip trailing ws from (char*) */ size_t strip_end_ws(char *str) { size_t last = 0; - for (size_t i = 0; str[i] != 0; ++i) + for (size_t i = 0; str[i] != 0; ++i) { if (!isspace(str[i])) last = i + 1; + } str[last] = '\0'; return last; } @@ -49,16 +50,18 @@ int tc_buf(struct tc_buf *buf) { buf->size = TC_BUF_INIT_SIZE; buf->used = 0; buf->data = (char *)malloc(buf->size); - if (buf->data == NULL) + if (buf->data == NULL) { return -1; + } return 0; } /* Append len bytes of memory from str pointed memory */ int tc_buf_append(struct tc_buf *buf, void *str, size_t len) { if (buf->size - buf->used < len) { - if (buf->size < len) + if (buf->size < len) { buf->size = len; + } buf->size *= TC_BUF_MULTIPLIER; char *nd = (char *)realloc(buf->data, buf->size); if (nd == NULL) @@ -125,11 +128,11 @@ size_t tc_buf_str_delete(struct tc_buf *buf, size_t len) { * and delete delimiter (last num bytes) */ void tc_buf_cmdfy(struct tc_buf *buf, size_t num) { - tc_buf_delete(buf, num); - buf->data[buf->size] = '\0'; - for (int i = 0; i < buf->used; ++i) + tc_buf_str_delete(buf, num); + for (int i = 0; i < buf->used; ++i) { if (buf->data[i] == '\n') buf->data[i] = ' '; + } } /* Remove trailing ws from STR */ diff --git a/client/tarantool/tc_cli.c b/client/tarantool/tc_cli.c index e418e559a6adca571183b99f064701fb8246d205..ca73a869ea0e947a4aa8aa425b67dc28aa7427b7 100644 --- a/client/tarantool/tc_cli.c +++ b/client/tarantool/tc_cli.c @@ -116,10 +116,6 @@ static struct tnt_lex_keyword tc_lex_keywords[] = { "loadfile", 8, TC_LOADFILE }, { "s", 1, TC_SETOPT}, { "setopt", 6, TC_SETOPT}, - { "delim", 5, TC_SETOPT_DELIM}, - { "delimi", 6, TC_SETOPT_DELIM}, - { "delimit", 7, TC_SETOPT_DELIM}, - { "delimite", 8, TC_SETOPT_DELIM}, { "delimiter", 9, TC_SETOPT_DELIM}, { NULL, 0, TNT_TK_NONE } }; @@ -240,7 +236,7 @@ static void replace_newline(char *cmd) { int offset = 0; for (int i = 0; i < len - 1; ++i) if (cmd[i] == '\\' && cmd[i + 1] == 'n') - cmd[i - offset++] = '\n'; + cmd[i++ - offset++] = '\n'; else if (offset != 0) cmd[i - offset] = cmd[i]; cmd[len - offset] = '\0'; @@ -283,8 +279,9 @@ tc_cmd_try(char *cmd, size_t size, int *reconnect) case TC_SETOPT: switch (tnt_lex(&lex, &tk)) { case TC_SETOPT_DELIM: - if (tnt_lex(&lex, &tk) != '=') + if (tnt_lex(&lex, &tk) != '=') { tnt_lex_push(&lex, tk); + } if (tnt_lex(&lex, &tk) == TNT_TK_STRING) { if (!TNT_TK_S(tk)->size) { tc.opt.delim = ""; @@ -403,9 +400,9 @@ static char* tc_cli_readline_pipe() { ungetc(c_t, stdin); wctomb(str + pos++, 0); break; - } - else + } else { pos += wctomb(str + pos, c); + } } if (pos == 1 && c == WEOF) { free(str); @@ -492,7 +489,7 @@ int tc_cli(void) tc_buf_free(&cmd); break; } -} + } /* updating history file */ write_history(history);