diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2022-08-23 22:49:48 +0200 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2022-08-23 22:49:48 +0200 |
commit | 8d12fe885db09e08313fbf15a943653c39dead97 (patch) | |
tree | 89badeaf73886447972195aa86b5e29622738b78 | |
parent | cmd: add cmd_from_argv (diff) | |
download | cimple-8d12fe885db09e08313fbf15a943653c39dead97.tar.gz cimple-8d12fe885db09e08313fbf15a943653c39dead97.zip |
remove redundant code
-rw-r--r-- | src/cmd.c | 8 |
1 files changed, 2 insertions, 6 deletions
@@ -67,9 +67,6 @@ static void arr_pack(char *dest, int argc, char **argv) static int arr_unpack(char **argv, int argc, const char *src) { - for (int i = 0; i < argc; ++i) - argv[i] = NULL; - for (int i = 0; i < argc; ++i) { size_t len = strlen(src); @@ -143,13 +140,12 @@ int cmd_recv(int fd, struct cmd *cmd) return ret; cmd->argc = calc_arr_len(buf, len); - cmd->argv = malloc(cmd->argc * sizeof(char *)); + cmd->argv = calloc(cmd->argc, sizeof(char *)); if (!cmd->argv) { - print_errno("malloc"); + print_errno("calloc"); ret = -1; goto free_buf; } - memset(cmd->argv, 0, cmd->argc * sizeof(char *)); ret = arr_unpack(cmd->argv, cmd->argc, buf); if (ret < 0) |