about summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorMarek Chalupa <chalupa@fi.muni.cz>2020-01-28 15:29:37 +0100
committerCristian Cadar <c.cadar@imperial.ac.uk>2020-04-08 13:23:45 +0100
commit647a539052d11a2e96989ffa5dfc3fb1b021ca3f (patch)
tree08a01f3ee0869d9b112146434eb1ba672d1c9bf1
parentd4f759bcb0280cf36b14d1be4fa4c3e109958ae0 (diff)
downloadklee-647a539052d11a2e96989ffa5dfc3fb1b021ca3f.tar.gz
test: add a new test for readStringAtAddress
Read strings from different parts of objects.
-rw-r--r--test/Feature/ReadStringAtAddress.c31
1 files changed, 31 insertions, 0 deletions
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;
+}