]> granicus.if.org Git - clang/commitdiff
Check the canonical parameter type with getAs<>() in a static checker
authorReid Kleckner <reid@kleckner.net>
Mon, 24 Jun 2013 16:56:16 +0000 (16:56 +0000)
committerReid Kleckner <reid@kleckner.net>
Mon, 24 Jun 2013 16:56:16 +0000 (16:56 +0000)
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

lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
test/Analysis/security-syntax-checks.m

index 63080ea230f87d092b8fab5b4cf420c5539b9f22..ca5ea32ef81e17f406839982a0bec2d9516eee3b 100644 (file)
@@ -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<PointerType>(FPT->getArgType(0));
+  const PointerType *PT = FPT->getArgType(0)->getAs<PointerType>();
   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<PointerType>(FPT->getArgType(1));
+  const PointerType *PT = FPT->getArgType(1)->getAs<PointerType>();
   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<PointerType>(FPT->getArgType(0));
+  const PointerType *PT = FPT->getArgType(0)->getAs<PointerType>();
   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<PointerType>(FPT->getArgType(i));
+    const PointerType *PT = FPT->getArgType(i)->getAs<PointerType>();
     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<PointerType>(FTP->getArgType(0));
+    const PointerType *PT = FTP->getArgType(0)->getAs<PointerType>();
     if (!PT)
       return;
 
index 1df8a408a69798bb425ac416790a6e5231b090ef..4ffd9a0b490742d0285677b27934fe196de0d294 100644 (file)
@@ -82,10 +82,11 @@ void test_setuid()
 }
 
 // <rdar://problem/6337100> 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);