view clang/docs/analyzer/checkers/callandmessage_example.c @ 173:0572611fdcc8 llvm10 llvm12

reorgnization done
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 11:55:54 +0900
parents 1d019706d866
children
line wrap: on
line source

//C
void test() {
   void (*foo)(void);
   foo = 0;
   foo(); // warn: function pointer is null
 }

 // C++
 class C {
 public:
   void f();
 };

 void test() {
   C *pc;
   pc->f(); // warn: object pointer is uninitialized
 }

 // C++
 class C {
 public:
   void f();
 };

 void test() {
   C *pc = 0;
   pc->f(); // warn: object pointer is null
 }

 // Objective-C
 @interface MyClass : NSObject
 @property (readwrite,assign) id x;
 - (long double)longDoubleM;
 @end

 void test() {
   MyClass *obj1;
   long double ld1 = [obj1 longDoubleM];
     // warn: receiver is uninitialized
 }

 // Objective-C
 @interface MyClass : NSObject
 @property (readwrite,assign) id x;
 - (long double)longDoubleM;
 @end

 void test() {
   MyClass *obj1;
   id i = obj1.x; // warn: uninitialized object pointer
 }

 // Objective-C
 @interface Subscriptable : NSObject
 - (id)objectAtIndexedSubscript:(unsigned int)index;
 @end

 @interface MyClass : Subscriptable
 @property (readwrite,assign) id x;
 - (long double)longDoubleM;
 @end

 void test() {
   MyClass *obj1;
   id i = obj1[0]; // warn: uninitialized object pointer
 }