cppcheck gives
CWE: 562
Returning object that points to local variable 'u' that will be invalid when returning.
on the line retval.s = loword(*(unsigned int *)&u);
But, if I'm right, the address of u is dereferenced and so its value is returned into retval.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I use cppcheck 2.5 from the GUI and I select Analyze >> Folder pointing to the folder with all my source files (.c and .h).
I get the same result if I copy and paste the code snippet into an empty file.c and select Analyze >> File.
I set the C standard to C99
I find the same warning as you, but moreover I get CWE: 562 as an error (not a warning).
Last edit: vix 2021-09-15
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
cppcheck gives
CWE: 562
Returning object that points to local variable 'u' that will be invalid when returning.
on the line
retval.s = loword(*(unsigned int *)&u);
But, if I'm right, the address of
u
is dereferenced and so its value is returned intoretval
.Which version do you use, and how do you call cppcheck? With current head, I get
but not the warning you describe.
I use cppcheck 2.5 from the GUI and I select Analyze >> Folder pointing to the folder with all my source files (.c and .h).
I get the same result if I copy and paste the code snippet into an empty file.c and select Analyze >> File.
I set the C standard to C99
I find the same warning as you, but moreover I get CWE: 562 as an error (not a warning).
Last edit: vix 2021-09-15
Ok, I can reproduce it with 2.5. You can either use a current build, or wait for 2.6.
-- sorry, wrong thread --
Last edit: Martin Brieg 2021-09-17