Please, find attached a simple C file with 2 search-type functions which return a pointer to the desired element in the array passed as argument. As C automatically passes arrays to functions by reference, I would expect no errors of type "returnDanglingLifetime" in any of the 2 search-type functions.
Running cppcheck v1.88 in Ubuntu 16.04 produces the following output:
[false_positive.c:27] -> [false_positive.c:21] -> [false_positive.c:30]: (error) Returning pointer to local variable 'array' that will be invalid when returning.
Cppcheck finds 1 error in just one of them, which is quite strange as both functions are quite similar. Interestingly enough, if we remove the break sentence (line 39) from the other search-type function, then cppcheck finds the same error in both functions.
Please, find attached a simple C file with 2 search-type functions which return a pointer to the desired element in the array passed as argument. As C automatically passes arrays to functions by reference, I would expect no errors of type "returnDanglingLifetime" in any of the 2 search-type functions.
Running cppcheck v1.88 in Ubuntu 16.04 produces the following output:
[false_positive.c:27] -> [false_positive.c:21] -> [false_positive.c:30]: (error) Returning pointer to local variable 'array' that will be invalid when returning.
Cppcheck finds 1 error in just one of them, which is quite strange as both functions are quite similar. Interestingly enough, if we remove the break sentence (line 39) from the other search-type function, then cppcheck finds the same error in both functions.
Kind regards,
This does not reproduce with 2.3.