shared/shell: Fix scan-build error
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Tue, 30 Aug 2022 21:37:27 +0000 (14:37 -0700)
committerAyush Garg <ayush.garg@samsung.com>
Mon, 15 May 2023 09:25:54 +0000 (14:55 +0530)
This fixes the following error:

src/shared/shell.c:1135:19: warning: Null pointer passed to 1st
parameter expecting 'nonnull'
                        data.timeout = atoi(optarg);
                                       ^~~~~~~~~~~~

Signed-off-by: Manika Shrivastava <manika.sh@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
src/shared/shell.c

index 4cf0cda..8b47379 100644 (file)
@@ -1100,6 +1100,7 @@ void bt_shell_init(int argc, char **argv, const struct bt_shell_opt *opt)
        struct option options[256];
        char optstr[256];
        size_t offset;
+       char *endptr = NULL;
 
        offset = sizeof(main_options) / sizeof(struct option);
 
@@ -1131,7 +1132,11 @@ void bt_shell_init(int argc, char **argv, const struct bt_shell_opt *opt)
                        data.mode = 1;
                        goto done;
                case 't':
-                       data.timeout = atoi(optarg);
+                       if (optarg)
+                               data.timeout = strtol(optarg, &endptr, 0);
+
+                       if (!endptr || *endptr != '\0')
+                               printf("Unable to parse timeout\n");
                        break;
                case 'z':
                        data.zsh = 1;