Skip to content
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

lwm2m: uninitialized variable in this function #32853

Closed
sinkyl opened this issue Mar 4, 2021 · 7 comments · Fixed by #32882
Closed

lwm2m: uninitialized variable in this function #32853

sinkyl opened this issue Mar 4, 2021 · 7 comments · Fixed by #32882
Assignees
Labels
area: LWM2M bug The issue is a bug, or the PR is fixing a bug

Comments

@sinkyl
Copy link

sinkyl commented Mar 4, 2021

Describe the bug
With Network, LwM2M and by default CONFIG_LWM2M_RW_JSON_SUPPORT=y in Zephyr 2.5 this warning show up:

/zephyrproject/zephyr/subsys/net/lib/lwm2m/lwm2m_rw_json.c:147:16: warning: 'c' may be used uninitialized in this function [-Wmaybe-uninitialized] 147 | uint8_t cont, c;

Environment (please complete the following information):

  • OS: Linux,
  • Toolchain: Zephyr SDK
@sinkyl sinkyl added the bug The issue is a bug, or the PR is fixing a bug label Mar 4, 2021
@erwango erwango changed the title uninitialized variable in this function lwm2m: uninitialized variable in this function Mar 4, 2021
@rlubos
Copy link
Contributor

rlubos commented Mar 4, 2021

How to reproduce this warning? I've tried to build with zephyr-sdk-0.12.3 for x86 and arm platforms and I didn't get it.

Besides, it doesn't look like a valid warning to me. Looking at the code in https:/zephyrproject-rtos/zephyr/blob/master/subsys/net/lib/lwm2m/lwm2m_rw_json.c#L144, the c variable can only be used after being set by the buf_read_u8() call. If the function call fails, the variable won't be used, otherwise it should hold a valid value.

@sinkyl
Copy link
Author

sinkyl commented Mar 4, 2021

Try with:
CONFIG_NEWLIB_LIBC=y and
CONFIG_DEBUG=y -> just in case you don't have it...

The warning show up when newlib is set to y.

@rlubos
Copy link
Contributor

rlubos commented Mar 4, 2021

Thanks, now I got it. I wonder how would these options affect the build to trigger the warning to show up...
Anyway, I still don't see anything wrong in the logic, so I'll just add some initial value to the variable to silence the warning.

@rlubos
Copy link
Contributor

rlubos commented Mar 4, 2021

I've submited a fix: #32882

@sinkyl
Copy link
Author

sinkyl commented Mar 4, 2021

I don't know either...
We set the default value to 0U, what you think ??? It should be fine no ?

@rlubos
Copy link
Contributor

rlubos commented Mar 4, 2021

We set the default value to 0U, what you think ??? It should be fine no ?

Yes, that's what I did as well

@sinkyl
Copy link
Author

sinkyl commented Mar 4, 2021

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: LWM2M bug The issue is a bug, or the PR is fixing a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants