[cfe-commits] [PATCH] Fix for PR7218, and analyzer support for calloc()

Jordy Rose jediknil at belkadan.com
Mon May 31 20:34:03 PDT 2010


On Tue, 1 Jun 2010 11:04:18 +0800, Zhongxing Xu <xuzhongxing at gmail.com>
wrote:
> Hi Jordy,
> 
> I applied most of your patch, except that I adopted 'bindDefault'
approach
> to set the default value, since it does not touch GRExprEngine. Thanks
for
> working on this!

Great! Thanks to you and Ted for all the real work on it, and helping me
get into this code.

As a last footnote, a suggested addition to PR7218.c: test the equivalent
case for a malloc region. (It's working fine, but seems like a good idea to
prevent regression.)
-------------- next part --------------
Index: test/Analysis/PR7218.c
===================================================================
--- test/Analysis/PR7218.c	(revision 105264)
+++ test/Analysis/PR7218.c	(working copy)
@@ -1,6 +1,20 @@
-// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-store region -verify %s
+// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-store region -analyzer-experimental-checks -analyzer-experimental-internal-checks -verify %s
+typedef typeof(sizeof(int)) size_t;
+void *malloc(size_t);
+void free(void *);
+
 char PR7218(char a) {
     char buf[2];
     buf[0] = a;
     return buf[1]; // expected-warning {{Undefined or garbage value returned to caller}}
 }
+
+char PR7218_malloc() {
+    char *buf = malloc(2);
+    *buf = 0;
+    char result;
+    if (buf[0]) result = *(char*)0; // no-warning
+    if (buf[1]) result = '!'; // expected-warning {{garbage}}
+    free(buf);
+    return result;
+}


More information about the cfe-commits mailing list