From 647a539052d11a2e96989ffa5dfc3fb1b021ca3f Mon Sep 17 00:00:00 2001 From: Marek Chalupa Date: Tue, 28 Jan 2020 15:29:37 +0100 Subject: test: add a new test for readStringAtAddress Read strings from different parts of objects. --- test/Feature/ReadStringAtAddress.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 test/Feature/ReadStringAtAddress.c diff --git a/test/Feature/ReadStringAtAddress.c b/test/Feature/ReadStringAtAddress.c new file mode 100644 index 00000000..64766282 --- /dev/null +++ b/test/Feature/ReadStringAtAddress.c @@ -0,0 +1,31 @@ +extern void klee_warning(const char *); + +// RUN: %clang %s -g -emit-llvm %O0opt -c -o %t.bc +// RUN: rm -rf %t.klee-out +// RUN: %klee --output-dir=%t.klee-out %t.bc 2>&1 | FileCheck %s + +int main(void) { + char strings[] = {'s', 't', 'r', '1', '\0', + 's', 't', 'r', '2', '\0', + 's', 't', 'r', '3', '\0'}; + + klee_warning(strings); + // CHECK: WARNING: main: str1 + klee_warning(strings+5); + // CHECK: WARNING: main: str2 + klee_warning(strings+2); + // CHECK: WARNING: main: r1 + klee_warning(strings+10); + // CHECK: WARNING: main: str3 + klee_warning(strings+6); + // CHECK: WARNING: main: tr2 + + char bytes[] = {'a', 'b', 'c', 'd'}; + // We should not crash, since it reads + // only up to the size of the object + klee_warning(bytes); + // CHECK: WARNING ONCE: String not terminated by \0 passed to one of the klee_ functions + // CHECK: WARNING: main: abcd + + return 0; +} -- cgit 1.4.1