brintos

brintos / llvm-project-archived public Read only

0
0
Text · 780 B · 5bcedda Raw
22 lines · cpp
1// RUN: %clangxx_msan -fsanitize-memory-track-origins -O0 %s -o %t && not %run %t >%t.out 2>&12// RUN: FileCheck %s < %t.out3// RUN: %clangxx_msan -fsanitize-memory-track-origins -O2 %s -o %t && not %run %t >%t.out 2>&14// RUN: FileCheck %s < %t.out5 6// This test relies on realloc from 100 to 101 being done in-place.7 8#include <stdlib.h>9int main(int argc, char **argv) {10  char *p = (char *)malloc(100);11  p = (char *)realloc(p, 101);12  char x = p[100];13  free(p);14  return x;15  // CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value16  // CHECK: {{#0 0x.* in main .*realloc-origin.cpp:}}[[@LINE-2]]17 18  // CHECK: Uninitialized value was created by a heap allocation19  // CHECK: {{#0 0x.* in .*realloc}}20  // CHECK: {{#1 0x.* in main .*realloc-origin.cpp:}}[[@LINE-9]]21}22