Menu

False positive: returnDanglingLifetime

heps
2019-07-04
2021-01-25
  • heps

    heps - 2019-07-04

    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,

     
  • CHR

    CHR - 2021-01-25

    This does not reproduce with 2.3.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.