brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.2 KiB · 2ff48cb Raw
29 lines · cpp
1// RUN: %clangxx -fsanitize=pointer-overflow %s -o %t2// RUN: %run %t  2 2>&1 | FileCheck %s --implicit-check-not="runtime error:" --check-prefix=ERR23// RUN: %run %t  1 2>&1 | FileCheck %s --implicit-check-not="runtime error:" --check-prefix=ERR14// RUN: %run %t  0 2>&1 | FileCheck %s --implicit-check-not="runtime error:" --check-prefix=SAFE5// RUN: %run %t -1 2>&1 | FileCheck %s --implicit-check-not="runtime error:" --check-prefix=SAFE6// RUN: %run %t -2 2>&1 | FileCheck %s --implicit-check-not="runtime error:" --check-prefix=SAFE7 8#include <stdio.h>9#include <stdint.h>10#include <stdlib.h>11 12int main(int argc, char *argv[]) {13  // SAFE-NOT: runtime error14  // ERR2: runtime error: pointer index expression with base {{.*}} overflowed to15  // ERR2: runtime error: pointer index expression with base {{.*}} overflowed to16  // ERR1: runtime error: applying non-zero offset to non-null pointer 0x{{.*}} produced null pointer17  // ERR1: runtime error: applying non-zero offset to non-null pointer 0x{{.*}} produced null pointer18 19  char *p = (char *)(UINTPTR_MAX);20 21  printf("%p\n", p + atoi(argv[1]));22 23  char *q = (char *)(UINTPTR_MAX);24 25  printf("%p\n", p - (-atoi(argv[1])));26 27  return 0;28}29