brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.1 KiB · 5842574 Raw
46 lines · c
1// RUN: rm -rf %t && mkdir %t && %clang_analyze_cc1 -analyzer-checker=core,optin.taint,debug.TaintTest,unix.Malloc %s -verify -analyzer-output=sarif-html -o %t%{fs-sep}out.sarif2// RUN: cat %t%{fs-sep}out.sarif | %normalize_sarif | diff -U1 -b %S/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif -3#include "../Inputs/system-header-simulator.h"4#include "../Inputs/system-header-simulator-for-malloc.h"5#define ERR -16int atoi(const char *nptr);7 8void f(void) {9  char s[80];10  scanf("%s", s);11  int d = atoi(s); // expected-warning {{tainted}}12}13 14void g(void) {15  void (*fp)(int);16  fp(12); // expected-warning {{Called function pointer is an uninitialized pointer value}}17}18 19int h(int i) {20  if (i == 0)21    return 1 / i; // expected-warning {{Division by zero}}22  return 0;23}24 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 33int unicode(void) {34  int løçål = 0;35  /* ☃ */ return 1 / løçål; // expected-warning {{Division by zero}}36}37 38int main(void) {39  f();40  g();41  h(0);42  leak(0);43  unicode();44  return 0;45}46