Skip to content

Commit 17e62bc

Browse files
ndrs-pstnashif
authored andcommitted
net: shell: ping: streamline parse_arg function by using shell_strtol
Switch from using direct `strtol` calls to `shell_strtol`. This change leverages the extensive error handling provided by `shell_strtol`. Signed-off-by: Pisit Sawangvonganan <[email protected]>
1 parent edaf94e commit 17e62bc

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

subsys/net/lib/shell/ping.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,10 @@ static int handle_ipv4_echo_reply(struct net_icmp_ctx *ctx,
199199

200200
static int parse_arg(size_t *i, size_t argc, char *argv[])
201201
{
202-
int res = -1;
202+
int res;
203+
int err;
204+
int base;
203205
const char *str = argv[*i] + 2;
204-
char *endptr;
205206

206207
if (*str == 0) {
207208
if (*i + 1 >= argc) {
@@ -212,14 +213,15 @@ static int parse_arg(size_t *i, size_t argc, char *argv[])
212213
str = argv[*i];
213214
}
214215

215-
errno = 0;
216216
if (strncmp(str, "0x", 2) == 0) {
217-
res = strtol(str, &endptr, 16);
217+
base = 16;
218218
} else {
219-
res = strtol(str, &endptr, 10);
219+
base = 10;
220220
}
221221

222-
if (errno || (endptr == str)) {
222+
err = 0;
223+
res = shell_strtol(str, base, &err);
224+
if (err != 0) {
223225
return -1;
224226
}
225227

0 commit comments

Comments
 (0)