valgrind error

I get the following errors with valgrind (and some leaks but I haven't
resolved them yet)

==4810== Invalid write of size 4
==4810== at 0x81BCE8A: clang::QualType::QualType() (Type.h:59)
==4810== by 0x820289A: clang::FunctionTypeProto::FunctionTypeProto(clang::QualType, clang::QualType*, unsigned, bool, clang::QualType) (Type.h:565)
[snip]

==4810== Address 0x42CFD10 is 0 bytes after a block of size 24 alloc'd
==4810== at 0x4021620: malloc (vg_replace_malloc.c:149)
==4810== by 0x81FF7C1: clang::ASTContext::getFunctionType(clang::QualType, clang::QualType*, unsigned, bool) (ASTContext.cpp:550)
[snip]

The following patch fixes it:

(it only removes 1 sizeof(QualType) if NumArgs is > 0)
If you prefer to avoid !!NumArgs (it is quite common in the linux kernel for
example, but it may be seen as an obfuscation by some people), I could use
(NumArgs ? 1 : 0)

--- AST/ASTContext.cpp (revision 40015)
+++ AST/ASTContext.cpp (working copy)
@@ -547,7 +547,7 @@
   // variable size array (for parameter types) at the end of them.
   FunctionTypeProto *FTP =
     (FunctionTypeProto*)malloc(sizeof(FunctionTypeProto) +
- (NumArgs-1)*sizeof(QualType));
+ (NumArgs-!!NumArgs)*sizeof(QualType));
   new (FTP) FunctionTypeProto(ResultTy, ArgArray, NumArgs, isVariadic,
                               Canonical);
   Types.push_back(FTP);

fix_valgrind.diff (624 Bytes)

Fixed, thanks:
http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20070716/001324.html

-Chris