Previously, even zero-length commands would be added to the history when
they shoudn't, e.g: just typing enter.
For example, if you type: FOO -> (ENTER) -> (ENTER),
then to get FOO from the history you would have to press the UP key
twice. It also saves a bit of memory.
Signed-off-by: Raphael S.Carvalho <raphael.scarv@gmail.com>
Signed-off-by: Matt Fleming <matt.fleming@intel.com>
printf("\033[?7h");
- /* Add the command to the history */
- comm_counter = malloc(sizeof(struct cli_command));
- comm_counter->command = malloc(sizeof(char) * (strlen(ret) + 1));
- strcpy(comm_counter->command, ret);
- list_add(&(comm_counter->list), &cli_history_head);
+ /* Add the command to the history if its length is larger than 0 */
+ len = strlen(ret);
+ if (len > 0) {
+ comm_counter = malloc(sizeof(struct cli_command));
+ comm_counter->command = malloc(sizeof(char) * (len + 1));
+ strcpy(comm_counter->command, ret);
+ list_add(&(comm_counter->list), &cli_history_head);
+ }
return len ? ret : NULL;
}