diff options
| author | Quentin Young <qlyoung@cumulusnetworks.com> | 2016-10-02 03:27:58 +0000 |
|---|---|---|
| committer | Quentin Young <qlyoung@cumulusnetworks.com> | 2016-10-02 03:27:58 +0000 |
| commit | 51d41d759bcd02506ec562018faace777dcee352 (patch) | |
| tree | 0dcc7f0cc9fdb5cc7fd985dfe12c757c3515f5b3 /lib/command.c | |
| parent | c5bd4620b0a6f37ceb44e004eceda1a708585e5b (diff) | |
lib: Null-terminate tab completions char*[]
vtysh expects the result of a tab completion to
have a null pointer as the last element
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Diffstat (limited to 'lib/command.c')
| -rw-r--r-- | lib/command.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/command.c b/lib/command.c index 9d68f33989..405cf6de66 100644 --- a/lib/command.c +++ b/lib/command.c @@ -618,8 +618,9 @@ cmd_complete_command_lib (vector vline, struct vty *vty, int *status, int islib) // get token completions vector comps = cmd_complete_command_real (shifted_vline, vty, status); - ret = XMALLOC (MTYPE_TMP, vector_active (comps) * sizeof (char *)); - for (unsigned int i = 0; i < vector_active (comps); i++) + ret = XMALLOC (MTYPE_TMP, vector_active (comps) * sizeof (char *) + 1); + unsigned int i; + for (i = 0; i < vector_active (comps); i++) { struct cmd_token *token = vector_slot (comps, i); ret[i] = XSTRDUP (MTYPE_TMP, token->text); @@ -627,6 +628,7 @@ cmd_complete_command_lib (vector vline, struct vty *vty, int *status, int islib) del_cmd_token (token); } vector_free (comps); + ret[i] = NULL; vector_free(shifted_vline); vty->node = onode; @@ -635,14 +637,16 @@ cmd_complete_command_lib (vector vline, struct vty *vty, int *status, int islib) // get token completions vector comps = cmd_complete_command_real (vline, vty, status); - ret = XMALLOC (MTYPE_TMP, vector_active (comps) * sizeof (char *)); - for (unsigned int i = 0; i < vector_active (comps); i++) + ret = XMALLOC (MTYPE_TMP, vector_active (comps) * sizeof (char *) + 1); + unsigned int i; + for (i = 0; i < vector_active (comps); i++) { struct cmd_token *token = vector_slot (comps, i); ret[i] = XSTRDUP (MTYPE_TMP, token->text); vector_unset (comps, i); del_cmd_token (token); } + ret[i] = NULL; vector_free (comps); return ret; |
