From d9b06623487a1ab5155b9d7fc06576999fa1acd3 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 22 Jun 2015 01:28:48 +0300 Subject: Add examples. --- examples/cexample.c | 205 ++++++++++++++++++++++++++++++++++++++++++++++++ examples/cexample.sh | 3 + examples/cppexample.cpp | 77 ++++++++++++++++++ examples/cppexample.sh | 3 + 4 files changed, 288 insertions(+) create mode 100644 examples/cexample.c create mode 100755 examples/cexample.sh create mode 100644 examples/cppexample.cpp create mode 100755 examples/cppexample.sh (limited to 'examples') diff --git a/examples/cexample.c b/examples/cexample.c new file mode 100644 index 0000000..c450ffb --- /dev/null +++ b/examples/cexample.c @@ -0,0 +1,205 @@ +int k; + +int main(void) +{ +} + +void func1(int *ptr1, int *ptr2) +{ + if (ptr1 || ptr2) + { + *ptr2 = 400; + } + else + { + *ptr1 = 100; + } + *ptr1 = 200; + *ptr2 = 300; +} + +void func2(int *ptr1, int *ptr2) +{ + if (ptr1 || ptr2) + { + *ptr2 = 400; + return; + } + else + { + *ptr1 = 100; + } + + *ptr1 = 200; + *ptr2 = 300; +} + +void func3(int *ptr1, int *ptr2) +{ + int c; + if (k == c || !ptr1) + { + return; + } + else + { + *ptr1 = 100; + } + + *ptr1 = 200; + *ptr2 = 300; +} + +void func4(int *ptr1, int *ptr2) +{ + int c; + if (k == c || !ptr1 || !ptr2) + { + return; + } + else + { + *ptr1 = 100; + } + + *ptr1 = 200; + *ptr2 = 300; +} + +void func5(int *ptr1, int *ptr2) +{ + int c; + if (!ptr1 || !ptr2 || k == c) + { + c = 3; + } + else + { + *ptr1 = 100; + } + + *ptr1 = 200; + *ptr2 = 300; +} + +void func6(int *ptr1, int *ptr2) +{ + if (ptr1 && ptr2) + { + *ptr1 = 100; + *ptr2 = 200; + } + else + { + return; + } + + *ptr1 = 300; + *ptr2 = 400; +} + +void func7(int *ptr1, int *ptr2) +{ + if (!ptr1 && !ptr2) + { + *ptr1 = 100; + *ptr2 = 200; + } + else + { + return; + } + + *ptr1 = 300; + *ptr2 = 400; +} + +void func8(int *ptr1, int *ptr2) +{ + if (ptr1 && ptr2) + { + *ptr1 = 100; + *ptr2 = 200; + return; + } + else + { + *ptr1 = 300; + *ptr2 = 400; + return; + } + + *ptr1 = 500; + *ptr2 = 600; +} + +void func9(int *ptr1, int *ptr2) +{ + if (ptr1 || ptr2) + { + *ptr2 = 100; + return; + } + else + { + *ptr1 = 200; + return; + } + + *ptr1 = 300; + *ptr2 = 400; +} + +void func10(int *ptr1, int *ptr2) +{ + if (ptr1 && ptr2 && k) + { + *ptr1 = 100; + *ptr2 = 200; + return; + } + else + { + *ptr1 = 300; + *ptr2 = 400; + } + + *ptr1 = 500; + *ptr2 = 600; +} + +void func11(int *ptr1, int *ptr2) +{ + if (ptr1 && ptr2 || ptr1) + { + *ptr1 = 100; + *ptr2 = 200; + return; + } + else + { + *ptr1 = 300; + *ptr2 = 400; + } + + *ptr1 = 500; + *ptr2 = 600; +} + +void func12(int *ptr1, int *ptr2) +{ + if (ptr1 || !ptr1) + { + *ptr1 = 100; + *ptr2 = 200; + return; + } + else + { + *ptr1 = 300; + *ptr2 = 400; + } + + *ptr1 = 500; + *ptr2 = 600; +} diff --git a/examples/cexample.sh b/examples/cexample.sh new file mode 100755 index 0000000..eff04e5 --- /dev/null +++ b/examples/cexample.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +gcc-5 -fplugin=../astdumper.so -fplugin-arg-astdumper-command=detectnullpointers cexample.c diff --git a/examples/cppexample.cpp b/examples/cppexample.cpp new file mode 100644 index 0000000..46b3c01 --- /dev/null +++ b/examples/cppexample.cpp @@ -0,0 +1,77 @@ +class Data1 +{ + public: + int val; +}; + +int main(int) +{ +} + +class Object1 +{ + int k; + + void func1(Data1 *ptr1, Data1 *ptr2) + { + if (!ptr1 || ptr1->val == 100) + { + return; + } + + ptr1->val = 200; + } + + void func2(Data1 *ptr1, Data1 *ptr2) + { + if (ptr1 && ptr1->val == 100) + { + ptr1->val = 200; + return; + } + + ptr1->val = 300; + } + + void func3(Data1 *ptr1, Data1 *ptr2) + { + if (ptr1 || ptr1->val == 100) + { + return; + } + + ptr1->val = 200; + } + + void func4(Data1 *ptr1, Data1 *ptr2) + { + if (!ptr1 && ptr1->val == 100) + { + return; + } + + ptr1->val = 200; + } + + void func5(Data1 *ptr1, Data1 *ptr2) + { + if ((!ptr1 || ptr1->val == 100) || (!ptr2 || ptr2->val == 200)) + { + return; + } + + ptr1->val = 300; + ptr2->val = 400; + } + + void func6(Data1 *ptr1, Data1 *ptr2) + { + if ((!ptr1 || ptr1->val == 100) && (!ptr2 || ptr2->val == 200)) + { + return; + } + + ptr1->val = 300; + ptr2->val = 400; + } +}; diff --git a/examples/cppexample.sh b/examples/cppexample.sh new file mode 100755 index 0000000..d6ff401 --- /dev/null +++ b/examples/cppexample.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +g++-5 -fplugin=../cppastdumper.so -fplugin-arg-cppastdumper-command=detectnullpointers cppexample.cpp -- cgit v1.2.3-70-g09d2