Просмотр исходного кода

Merge branch 'bugfix/console_empty_command' into 'master'

console: handle empty input to esp_console_run correctly

See merge request !1390

Ivan Grokhotkov 8 лет назад
Родитель
Сommit
2bba4a77c4

+ 3 - 1
components/console/commands.c

@@ -185,7 +185,9 @@ esp_err_t esp_console_run(const char* cmdline, int* cmd_ret)
 
     size_t argc = esp_console_split_argv(s_tmp_line_buf, argv,
             s_config.max_cmdline_args);
-
+    if (argc == 0) {
+        return ESP_ERR_INVALID_ARG;
+    }
     const cmd_item_t* cmd = find_command_by_name(argv[0]);
     if (cmd == NULL) {
         return ESP_ERR_NOT_FOUND;

+ 2 - 0
components/console/esp_console.h

@@ -107,6 +107,8 @@ esp_err_t esp_console_cmd_register(const esp_console_cmd_t *cmd);
  * @param[out] cmd_ret return code from the command (set if command was run)
  * @return
  *      - ESP_OK, if command was run
+ *      - ESP_ERR_INVALID_ARG, if the command line is empty, or only contained
+ *        whitespace
  *      - ESP_ERR_NOT_FOUND, if command with given name wasn't registered
  *      - ESP_ERR_INVALID_STATE, if esp_console_init wasn't called
  */

+ 2 - 0
examples/system/console/main/console_example_main.c

@@ -153,6 +153,8 @@ void app_main()
         esp_err_t err = esp_console_run(line, &ret);
         if (err == ESP_ERR_NOT_FOUND) {
             printf("Unrecognized command\n");
+        } else if (err == ESP_ERR_INVALID_ARG) {
+            // command was empty
         } else if (err == ESP_OK && ret != ESP_OK) {
             printf("Command returned non-zero error code: 0x%x\n", ret);
         } else if (err != ESP_OK) {