-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LE Audio shell strtoX fixes #54165
LE Audio shell strtoX fixes #54165
Conversation
792398f
to
7c5bb21
Compare
58ad87e
to
c8ff3b1
Compare
int result; | ||
int step = strtol(argv[1], NULL, 0); | ||
unsigned long step; | ||
int result = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should use the same name for error in all functions, err
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disagree; I think it's better to just use the already defined value to keep the number of lines changed to a minimum.
|
||
if (step > UINT8_MAX || step == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like you changed logic, no check for step == 0
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch - Thanks!
return -ENOEXEC; | ||
} | ||
|
||
if (location > UINT32_MAX) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the logic is changed, it was UINT16_MAX
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, perhaps that should have been a separate commit. Should I add another commit for that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a commit to fix this in the PR
count = strtoul(argv[1], NULL, 10); | ||
count = shell_strtoul(argv[5], 0, &ret); | ||
if (ret != 0) { | ||
shell_error(sh, "Could not parse count: %d", ret); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better use the same variable for error, err
.
unsigned long order; | ||
int err = 0; | ||
|
||
order = shell_strtol(argv[1], 0, &err); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shell_strtoul
?
c8ff3b1
to
a0fc36c
Compare
|
||
if (start_scan != 0 && start_scan != 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shell_strtobool
has different logic, at the end it converts unsigned long
to bool
, so any number > 0 is true, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. I was unsure about whether I should just use shell_strtobool
directly, or actually check if the value was > 1, but decided on the former, as just using shell_strtobool
would be more consistent with other shell commands that use that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, looks reasonable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, although I would use the same error code err
instead of result
, etc.
Making all the audio shell implementations more consistent can be postponed to a separate PR :) |
Verify all values returned by calls to strtoX and convert to the shell_strtoX functions. Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Verify all values returned by calls to strtoX and convert to the shell_strtoX functions. Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Verify all values returned by calls to strtoX and convert to the shell_strtoX functions. Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Verify all values returned by calls to strtoX and convert to the shell_strtoX functions. Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Verify all values returned by calls to strtoX and convert to the shell_strtoX functions. Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Verify all values returned by calls to strtoX and convert to the shell_strtoX functions. Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
6c4c5df
to
8869541
Compare
Found a few more with incorrect type |
subsys/bluetooth/shell/mcc.c
Outdated
unsigned long order; | ||
int result = 0; | ||
|
||
order = shell_strtol(argv[1], 0, &result); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
order = shell_strtol(argv[1], 0, &result); | |
order = shell_strtoul(argv[1], 0, &result); |
inst_index = strtol(argv[1], NULL, 0); | ||
if (inst_index < 0 || inst_index > UINT8_MAX) { | ||
shell_error(sh, "Invalid index"); | ||
inst_index = shell_strtoul(argv[1], 0, &result); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a comment/TODO that this can be pulled out as a function since this code is repeated many times?
return -ENOEXEC; | ||
} | ||
|
||
if (offset > BT_VOCS_MAX_OFFSET || offset < BT_VOCS_MIN_OFFSET) { | ||
shell_error(sh, "Offset shall be %d-%d, was %d", | ||
shell_error(sh, "Offset shall be %d-%d, was %ld", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missed opportunity for using IN_RANGE
if (gain > INT8_MAX || gain < INT8_MIN) { | ||
shell_error(sh, "Offset shall be %d-%d, was %d", | ||
shell_error(sh, "Gain shall be %d-%d, was %d", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use IN_RANGE?
Verify all values returned by calls to strtoX and convert to the shell_strtoX functions. Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Verify all values returned by calls to strtoX and convert to the shell_strtoX functions. Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Verify all values returned by calls to strtoX and convert to the shell_strtoX functions. Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Verify all values returned by calls to strtoX and convert to the shell_strtoX functions. Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Verify all values returned by calls to strtoX and convert to the shell_strtoX functions. Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Verify all values returned by calls to strtoX and convert to the shell_strtoX functions. Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Verify all values returned by calls to strtoX and convert to the shell_strtoX functions. Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
The location value is a uint32_t, and not uint16_t. Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Verify all values returned by calls to strtoX and convert to the shell_strtoX functions. Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Verify all values returned by calls to strtoX and convert to the shell_strtoX functions. Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
8869541
to
59ab703
Compare
Ensures that all
strtoX
calls are handled correctly, and moves to use theshell_strtoX
functionsFixes most of the bugs reported in #54101
Fixes #54101