llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

scan-build does not catch returning pointers to local storage

Open llvmbot opened this issue 10 years ago • 2 comments

Bugzilla Link 26826
Version unspecified
OS Linux
Attachments test case
Reporter LLVM Bugzilla Contributor
CC @devincoughlin

Extended Description

The attached file shows a function returns a pointer to an array in its local stack frame to its caller. This is dangerous, because an interrupt or other intervening function call made by the caller before referencing this returned pointer can clobber this region of memory, resulting in garbage values.

I would have expected the static analyzer to flag this as questionable, but

scan-build clang -O3 -Wall -c returns_pointer_to_local.c

yields only:

scan-build: Using '/home/swilliams-local/src/llvm-build/bin/clang-3.9' for static analysis scan-build: Removing directory '/tmp/scan-build-2016-03-02-165148-28031-1' because it contains no reports. scan-build: No bugs found.

llvmbot avatar Mar 03 '16 02:03 llvmbot

Reproduced. I'm surprised that the StackAddrEscapeChecker doesn't catch this!

Tracked internally by rdar://problem/24944831.

devincoughlin avatar Mar 03 '16 03:03 devincoughlin

assigned to @tkremenek

llvmbot avatar Mar 03 '16 02:03 llvmbot