diff mbox series

[BlueZ,2/2] shared/shell: Fix scan-build error

Message ID 20220830214215.1137276-2-luiz.dentz@gmail.com
State New
Headers show
Series [BlueZ,1/2] client/player: Fix checkpatch warning | expand

Commit Message

Luiz Augusto von Dentz Aug. 30, 2022, 9:42 p.m. UTC
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This fixes the following error:

src/shared/shell.c:1135:19: warning: Null pointer passed to 1st
parameter expecting 'nonnull'
                        data.timeout = atoi(optarg);
                                       ^~~~~~~~~~~~
---
 src/shared/shell.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/src/shared/shell.c b/src/shared/shell.c
index 4658819a4bde..46ba8112cfb0 100644
--- a/src/shared/shell.c
+++ b/src/shared/shell.c
@@ -1101,6 +1101,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);
 
@@ -1132,7 +1133,9 @@  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);
+			data.timeout = strtol(optarg, &endptr, 0);
+			if (!endptr || *endptr != '\0')
+				printf("Unable to parse timeout\n");
 			break;
 		case 'z':
 			data.zsh = 1;