]> granicus.if.org Git - clang/commit
[analyzer] Make realloc(ptr, 0) handling equivalent to malloc(0).
authorDevin Coughlin <dcoughlin@apple.com>
Tue, 22 Sep 2015 22:47:14 +0000 (22:47 +0000)
committerDevin Coughlin <dcoughlin@apple.com>
Tue, 22 Sep 2015 22:47:14 +0000 (22:47 +0000)
commitdb0f9f00d23c343c6a142be9485c2b9abd72a503
treecab806baeebdb88f7373a51c0bd97db5ce1b0e52
parent8ef8ffcccf3af28d2dba8ce1d3ace2346538a697
[analyzer] Make realloc(ptr, 0) handling equivalent to malloc(0).

Currently realloc(ptr, 0) is treated as free() which seems to be not correct. C
standard (N1570) establishes equivalent behavior for malloc(0) and realloc(ptr,
0): "7.22.3 Memory management functions calloc, malloc, realloc: If the size of
the space requested is zero, the behavior is implementation-defined: either a
null pointer is  returned, or the behavior is as if the size were some nonzero
value, except that the returned pointer shall not be used to access an object."
The patch equalizes the processing of malloc(0) and realloc(ptr,0). The patch
also enables unix.Malloc checker to detect references to zero-allocated memory
returned by realloc(ptr,0) ("Use of zero-allocated memory" warning).

A patch by Антон Ярцев!

Differential Revision: http://reviews.llvm.org/D9040

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@248336 91177308-0d34-0410-b5e6-96231b3b80d8
lib/StaticAnalyzer/Checkers/MallocChecker.cpp
test/Analysis/malloc.c