int main() { int *buf[4]; buf[0] = malloc(sizeof(int)*4); buf[1] = malloc(sizeof(int)); buf[2] = 0; // gets malloc'd buf[3] = (int*) 0xdeadbeef; // boom buf[0][0] = 10; buf[0][1] = 42; buf[1][0] = 20; int i = klee_urange(0,4); int new_size = 2 * sizeof(int) * klee_urange(0,2); // 0 or 8 // whee, party time, needs to: // Fork if size == 0, in which case all buffers get free'd and // we will crash in prints below. // Fork if buf[s] == 0, in which case the buffer gets malloc'd (for s==2) // Fork on other buffers (s in [0,1]) and do realloc // for s==0 this is shrinking // for s==1 this is growing buf[i] = realloc(buf[i], new_size); if (new_size == 0) { assert(!buf[2]); // free(0) is a no-op if (i==0) assert(!buf[0] && buf[1]); if (i==1) assert(buf[0] && !buf[1]); assert(i != 3); // we should have crashed on free of invalid } else { assert(new_size == sizeof(int)*2); assert(buf[0][0] == 10); assert(buf[0][1] == 42); // make sure copied assert(buf[1][0] == 20); if (i==1) { int x = buf[1][1]; } // should be safe if (i==2) { int x = buf[2][0]; } // should be safe assert(i != 3); // we should have crashed on realloc of invalid } return 0; }
int main() { int *buf[4]; int i,s,t; for (i=0; i<4; i++) buf[i] = make_int((i+1)*2); s = klee_urange(0,4); int x = *buf[s]; if (x == 4) if (s!=1) abort(); printf("x\n"); fflush(stdout); return 0; }
int main(int argc, char ** argv) { int a = klee_urange(0,3); int b; // fork states switch(a) { case 0: b = -0; break; case 1: b = -1; break; case 2: b = -2; break; default: assert(false && "Impossible switch target"); } // test 80-bit external dispatch long double d = powl((long double)-11.0, (long double)a); // FIXME: Use CHECK-DAG: with FileCheck tool // CHECK-DAG: powl(-11.0,0)=1.0 // CHECK-DAG: powl(-11.0,1)=-11.0 // CHECK-DAG: powl(-11.0,2)=121.0 printf("powl(-11.0,%d)=%Lf\n", a, d); // test 80-bit fdiv long double e = (long double) 1 / (long double) b; // CHECK-DAG: 1/0=inf // CHECK-DAG: 1/1-1=-1.0 // CHECK-DAG: 1/-2=-0.50 printf("1/%d=%Lf\n", b, e); return 0; }