From efd9e1ef2ba69497829dde2af6a879b789662e9b Mon Sep 17 00:00:00 2001 From: Vedant Kumar Date: Thu, 1 Jun 2017 19:40:59 +0000 Subject: [ubsan] Runtime support for pointer overflow checking Patch by John Regehr and Will Dietz! Differential Revision: https://reviews.llvm.org/D20323 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@304461 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/ubsan/TestCases/Pointer/index-overflow.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 test/ubsan/TestCases/Pointer/index-overflow.cpp (limited to 'test/ubsan') diff --git a/test/ubsan/TestCases/Pointer/index-overflow.cpp b/test/ubsan/TestCases/Pointer/index-overflow.cpp new file mode 100644 index 000000000..eb7f95e85 --- /dev/null +++ b/test/ubsan/TestCases/Pointer/index-overflow.cpp @@ -0,0 +1,19 @@ +// RUN: %clangxx -fsanitize=pointer-overflow %s -o %t +// RUN: %t 1 2>&1 | FileCheck %s --check-prefix=ERR +// RUN: %t 0 2>&1 | FileCheck %s --check-prefix=SAFE +// RUN: %t -1 2>&1 | FileCheck %s --check-prefix=SAFE + +#include +#include +#include + +int main(int argc, char *argv[]) { + // SAFE-NOT: runtime error + // ERR: runtime error: pointer index expression with base {{.*}} overflowed to + + char *p = (char *)(UINTPTR_MAX); + + printf("%p\n", p + atoi(argv[1])); + + return 0; +} -- cgit v1.2.3