-
Notifications
You must be signed in to change notification settings - Fork 12
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
app_rpt: Incorrect usage of sizeof() function #207
Comments
These both look similar to the last issue Danny identified, where it's taking the address of a pointer. That is almost certainly not what is intended here. I think anything in the codebase with The typical usage for this type of thing with a pointer is to use In contrast, using As discussed before, sizeof should not be used directly for strlen. The usage is wrong and confusing. If the string is null terminated, I don't see why strcmp could not be used. |
Ah yes, I swapped those in my head. |
The sizeof() usage that @KB4MDD called out should be fixed. To see the issue, compile the following :
and when exec'd you'll get :
Using "sizeof(&mdcp)" is clearly not correct (it's the size of an address vs. the size of the allocation). The usage of sizeof(&expect) is also incorrect. |
The following functions appear to use the sizeof() function incorrectly.
apps/app_rpt/rpt_mdc1200.c
In mdc_1200_ack_status, line 209:
memset(mdcp, 0, sizeof(&mdcp));
This should be sizeof(mdcparams)
apps/app_rpt/rpt_uchameleon.c
In uchameleon_connect, line 73:
if ((count != 13) || (strncmp(expect, rxbuf + 4, sizeof(&expect)))) {
expect may need to be changed to a character array or change sizeof(&expect), or the literal 9, or strlen(expect).
Note: I am not sure why idbuf, ledbuf, and expect are declared as static. They probably should be char arrays and const.
The text was updated successfully, but these errors were encountered: