From: Reid Kleckner Date: Mon, 24 Jun 2013 16:56:16 +0000 (+0000) Subject: Check the canonical parameter type with getAs<>() in a static checker X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=dbcc7561f6964404c590f42454a249af5324fa44;p=clang Check the canonical parameter type with getAs<>() in a static checker This will prevent breakage when I introduce the DecayedType sugar node. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@184755 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp b/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp index 63080ea230..ca5ea32ef8 100644 --- a/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp +++ b/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp @@ -307,7 +307,7 @@ void WalkAST::checkCall_gets(const CallExpr *CE, const FunctionDecl *FD) { return; // Is the argument a 'char*'? - const PointerType *PT = dyn_cast(FPT->getArgType(0)); + const PointerType *PT = FPT->getArgType(0)->getAs(); if (!PT) return; @@ -349,7 +349,7 @@ void WalkAST::checkCall_getpw(const CallExpr *CE, const FunctionDecl *FD) { return; // Verify the second argument type is char*. - const PointerType *PT = dyn_cast(FPT->getArgType(1)); + const PointerType *PT = FPT->getArgType(1)->getAs(); if (!PT) return; @@ -391,7 +391,7 @@ void WalkAST::checkCall_mktemp(const CallExpr *CE, const FunctionDecl *FD) { return; // Verify that the argument is Pointer Type. - const PointerType *PT = dyn_cast(FPT->getArgType(0)); + const PointerType *PT = FPT->getArgType(0)->getAs(); if (!PT) return; @@ -568,7 +568,7 @@ bool WalkAST::checkCall_strCommon(const CallExpr *CE, const FunctionDecl *FD) { // Verify the type for both arguments. for (int i = 0; i < 2; i++) { // Verify that the arguments are pointers. - const PointerType *PT = dyn_cast(FPT->getArgType(i)); + const PointerType *PT = FPT->getArgType(i)->getAs(); if (!PT) return false; @@ -598,7 +598,7 @@ void WalkAST::checkCall_rand(const CallExpr *CE, const FunctionDecl *FD) { if (FTP->getNumArgs() == 1) { // Is the argument an 'unsigned short *'? // (Actually any integer type is allowed.) - const PointerType *PT = dyn_cast(FTP->getArgType(0)); + const PointerType *PT = FTP->getArgType(0)->getAs(); if (!PT) return; diff --git a/test/Analysis/security-syntax-checks.m b/test/Analysis/security-syntax-checks.m index 1df8a408a6..4ffd9a0b49 100644 --- a/test/Analysis/security-syntax-checks.m +++ b/test/Analysis/security-syntax-checks.m @@ -82,10 +82,11 @@ void test_setuid() } // CWE-338: Use of cryptographically weak prng +typedef unsigned short *ushort_ptr_t; // Test that sugar doesn't confuse the warning. int rand(void); double drand48(void); double erand48(unsigned short[3]); -long jrand48(unsigned short[3]); +long jrand48(ushort_ptr_t); void lcong48(unsigned short[7]); long lrand48(void); long mrand48(void);