1 // RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.security.taint,debug.TaintTest,unix.Malloc %s -verify -analyzer-output=sarif -o - | %normalize_sarif | diff -U1 -b %S/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif - 2 #include "../Inputs/system-header-simulator.h" 3 #include "../Inputs/system-header-simulator-for-malloc.h" 4 #define ERR -1 5 6 int atoi(const char *nptr); 7 f(void)8void f(void) { 9 char s[80]; 10 scanf("%s", s); 11 int d = atoi(s); // expected-warning {{tainted}} 12 } 13 g(void)14void g(void) { 15 void (*fp)(int); 16 fp(12); // expected-warning {{Called function pointer is an uninitialized pointer value}} 17 } 18 h(int i)19int h(int i) { 20 if (i == 0) 21 return 1 / i; // expected-warning {{Division by zero}} 22 return 0; 23 } 24 leak(int i)25int leak(int i) { 26 void *mem = malloc(8); 27 if (i < 4) 28 return ERR; // expected-warning {{Potential leak of memory pointed to by 'mem'}} 29 free(mem); 30 return 0; 31 } 32 unicode()33int unicode() { 34 int løçål = 0; 35 /* ☃ */ return 1 / løçål; // expected-warning {{Division by zero}} 36 } 37 main(void)38int main(void) { 39 f(); 40 g(); 41 h(0); 42 leak(0); 43 unicode(); 44 return 0; 45 } 46 47