#include<stdio.h>#include<stdlib.h>staticintsink;voidfoo(){int**pp=NULL;int*p=NULL;inta=20;intret;p=&a;pp=&p;ret=**pp;/*Tool should not detect this line as error*//*No ERROR:Uninitialized pointer*/sink=ret;}intmain(){foo();return0;}
And I get the danglingLifetime error. I think this case is not error. What do you think?
Checking E:\test2\test2\test.cpp ...
E:\test2\test2\test.cpp:15:2: error: Non-local variable 'sink' will use object that points to local variable 'a'. [danglingLifetime]
sink = ret;
^
E:\test2\test2\test.cpp:12:6: note: Address of variable taken here.
p = &a;
^
E:\test2\test2\test.cpp:10:6: note: Variable created here.
int a = 20;
^
E:\test2\test2\test.cpp:15:2: note: Non-local variable 'sink' will use object that points to local variable 'a'.
sink = ret;
^
Last edit: Geongu.Park 2021-08-11
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I write this code and run the cppcheck.
And I get the danglingLifetime error. I think this case is not error. What do you think?
Last edit: Geongu.Park 2021-08-11
Thanks for the report, I have created a ticket here: https://trac.cppcheck.net/ticket/10406