brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.6 KiB · f4cf1d8 Raw
45 lines · cpp
1// RUN: %clang_msan -Wno-alloc-size -fsanitize-recover=memory %s -o %t && not %run %t 2>&1 \2// RUN:     | FileCheck %s --check-prefix=CHECK3// RUN: %clang_msan -Wno-alloc-size -fsanitize-recover=memory -fsanitize-memory-track-origins=1 %s -o %t && not %run %t 2>&1 \4// RUN:     | FileCheck %s --check-prefixes=CHECK,DISCOUNT5// RUN: %clang_msan -Wno-alloc-size -fsanitize-recover=memory -fsanitize-memory-track-origins=2 %s -o %t && not %run %t 2>&1 \6// RUN:     | FileCheck %s --check-prefixes=CHECK,ORIGINS7 8#include <stdio.h>9#include <stdlib.h>10 11int main(int argc, char **argv) {12  {13    char *p1 = (char *)calloc(1, 0);14    printf("p1 is %p\n", p1);15    printf("Content of p1 is: %d\n", *p1);16    // CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value17    // CHECK: {{#0 0x.* in main .*zero_alloc.cpp:}}[[@LINE-2]]18    // DISCOUNT,ORIGINS: Uninitialized value is outside of heap allocation19    free(p1);20  }21 22  {23    char *p2 = (char *)calloc(0, 1);24    printf("p2 is %p\n", p2);25    printf("Content of p2 is: %d\n", *p2);26    // CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value27    // CHECK: {{#0 0x.* in main .*zero_alloc.cpp:}}[[@LINE-2]]28    // DISCOUNT,ORIGINS: Uninitialized value is outside of heap allocation29    free(p2);30  }31 32  {33    char *p3 = (char *)malloc(0);34    printf("p3 is %p\n", p3);35    printf("Content of p2 is: %d\n", *p3);36    // CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value37    // CHECK: {{#0 0x.* in main .*zero_alloc.cpp:}}[[@LINE-2]]38    // DISCOUNT: Uninitialized value was created by a heap allocation39    // ORIGINS: Uninitialized value is outside of heap allocation40    free(p3);41  }42 43  return 0;44}45