brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.3 KiB · 818806c Raw
59 lines · c
1// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -analyzer-checker=core,security.ArrayBound -Wno-implicit-function-declaration -verify %s2// RUN: %clang_analyze_cc1 -triple i386-apple-darwin10 -analyzer-checker=core,security.ArrayBound -Wno-implicit-function-declaration -DM32 -verify %s3// expected-no-diagnostics4 5#define UINT_MAX (~0u)6 7#ifdef M328 9#define X86_ARRAY_SIZE (UINT_MAX/2 + 4)10 11void testIndexTooBig(void) {12  char arr[X86_ARRAY_SIZE];13  char *ptr = arr + UINT_MAX/2;14  ptr += 2;  // index shouldn't overflow15  *ptr = 42; // no-warning16}17 18#else // 64-bit tests19 20#define ARRAY_SIZE 0x10000000021 22void testIndexOverflow64(void) {23  char arr[ARRAY_SIZE];24  char *ptr = arr + UINT_MAX/2;25  ptr += 2;  // don't overflow 64-bit index26  *ptr = 42; // no-warning27}28 29#define ULONG_MAX (~0ul)30#define BIG_INDEX (ULONG_MAX/16)31 32void testIndexTooBig64(void) {33  char arr[ULONG_MAX/8-1];34  char *ptr = arr + BIG_INDEX;35  ptr += 2;  // don't overflow 64-bit index36  *ptr = 42; // no-warning37}38 39#define SIZE 429496729640 41static unsigned size;42static void * addr;43static unsigned buf[SIZE];44 45void testOutOfBounds(void) {46  // Not out of bounds.47  buf[SIZE-1] = 1; // no-warning48}49 50void testOutOfBoundsCopy1(void) {51  memcpy(buf, addr, size); // no-warning52}53 54void testOutOfBoundsCopy2(void) {55  memcpy(addr, buf, size); // no-warning56}57 58#endif59