brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.0 KiB · 2cb8538 Raw
49 lines · c
1// RUN: %clang_analyze_cc1 -verify %s \2// RUN:   -analyzer-checker=core \3// RUN:   -analyzer-checker=unix \4// RUN:   -analyzer-checker=core.uninitialized \5// RUN:   -analyzer-config unix.DynamicMemoryModeling:Optimistic=true6 7typedef __typeof(sizeof(int)) size_t;8void *malloc(size_t);9void free(void *);10 11char stackBased1 (void) {12  char buf[2];13  buf[0] = 'a';14  return buf[1]; // expected-warning{{Undefined}}15}16 17char stackBased2 (void) {18  char buf[2];19  buf[1] = 'a';20  return buf[0]; // expected-warning{{Undefined}}21}22 23// Exercise the conditional visitor.24char stackBased3 (int *x) {25  char buf[2];26  int *y;27  buf[0] = 'a';28  if (!(y = x)) {29    return buf[1]; // expected-warning{{Undefined}}30  }31  return buf[0];32}33 34char heapBased1 (void) {35  char *buf = malloc(2);36  buf[0] = 'a';37  char result = buf[1]; // expected-warning{{uninitialized}}38  free(buf);39  return result;40}41 42char heapBased2 (void) {43  char *buf = malloc(2);44  buf[1] = 'a';45  char result = buf[0]; // expected-warning{{uninitialized}}46  free(buf);47  return result;48}49