Skip to content

Commit c120ffb

Browse files
ndrs-pstnashif
authored andcommitted
bluetooth: shell: avoid multiple strlen calls
Add `len` to store the result of `strlen(addr_arg)` to avoid multiple calls to `strlen` within the `for-loop` in `cmd_scan_filter_set_addr`. While the performance impact may be minimal in a shell context, storing `strlen(addr_arg)` in `len` ensures a single call, making the code more predictable and consistent. Signed-off-by: Pisit Sawangvonganan <[email protected]>
1 parent 3f95fd4 commit c120ffb

File tree

1 file changed

+3
-2
lines changed
  • subsys/bluetooth/host/shell

1 file changed

+3
-2
lines changed

subsys/bluetooth/host/shell/bt.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1769,16 +1769,17 @@ static int cmd_scan_filter_set_addr(const struct shell *sh, size_t argc,
17691769
{
17701770
const size_t max_cpy_len = sizeof(scan_filter.addr) - 1;
17711771
const char *addr_arg = argv[1];
1772+
size_t len = strlen(addr_arg);
17721773

17731774
/* Validate length including null terminator. */
1774-
if (strlen(addr_arg) > max_cpy_len) {
1775+
if (len > max_cpy_len) {
17751776
shell_error(ctx_shell, "Invalid address string: %s\n",
17761777
addr_arg);
17771778
return -ENOEXEC;
17781779
}
17791780

17801781
/* Validate input to check if valid (subset of) BT address */
1781-
for (size_t i = 0; i < strlen(addr_arg); i++) {
1782+
for (size_t i = 0; i < len; i++) {
17821783
const char c = addr_arg[i];
17831784
uint8_t tmp;
17841785

0 commit comments

Comments
 (0)