From 06fe1097d64cda5085a192cca4c872be3cd818b0 Mon Sep 17 00:00:00 2001 From: jdh8d <jdh8d@git.zephyr-software.com> Date: Mon, 8 Aug 2011 21:18:31 +0000 Subject: [PATCH] A few c++, dynamic-linked pgms that test heaprand with new/delete errors --- .gitattributes | 7 +++ c++_examples/Makefile | 68 +++++++++++++++++++++++++++++ c++_examples/hanoi++.cpp | 60 ++++++++++++++++++++++++++ c++_examples/newdel.cpp | 78 ++++++++++++++++++++++++++++++++++ c++_examples/newdel_broke1.cpp | 76 +++++++++++++++++++++++++++++++++ c++_examples/newdel_broke2.cpp | 76 +++++++++++++++++++++++++++++++++ c++_examples/newdel_broke3.cpp | 76 +++++++++++++++++++++++++++++++++ c++_examples/newdel_broke4.cpp | 76 +++++++++++++++++++++++++++++++++ tools/db/drop_my_tables.sh | 2 - 9 files changed, 517 insertions(+), 2 deletions(-) create mode 100644 c++_examples/Makefile create mode 100644 c++_examples/hanoi++.cpp create mode 100644 c++_examples/newdel.cpp create mode 100644 c++_examples/newdel_broke1.cpp create mode 100644 c++_examples/newdel_broke2.cpp create mode 100644 c++_examples/newdel_broke3.cpp create mode 100644 c++_examples/newdel_broke4.cpp diff --git a/.gitattributes b/.gitattributes index f0ddeb7ea..1f73cb7b0 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,5 +1,12 @@ * text=auto !eol /Makefile -text +c++_examples/Makefile -text +c++_examples/hanoi++.cpp -text +c++_examples/newdel.cpp -text +c++_examples/newdel_broke1.cpp -text +c++_examples/newdel_broke2.cpp -text +c++_examples/newdel_broke3.cpp -text +c++_examples/newdel_broke4.cpp -text chopzero_src/Makefile -text chopzero_src/chopzero.c -text demos/Makefile -text diff --git a/c++_examples/Makefile b/c++_examples/Makefile new file mode 100644 index 000000000..cfd749e0b --- /dev/null +++ b/c++_examples/Makefile @@ -0,0 +1,68 @@ + + +CC=DO_NOT_USE +CXX=DO_NOT_USE +CFLAGS=DO_NOT_USE +LD=DO_NOT_USE + +.SUFFIXES: .o .c .cpp .exe + +exes=hanoi++.exe newdel.exe newdel_broke1.exe newdel_broke2.exe newdel_broke3.exe newdel_broke4.exe + + +all: env_check ${exes} + + + +.PHONY: env_check + + +.o.exe: + g++ $< -o $@ + ${PEASOUP_HOME}/tools/ps_analyze.sh $@ $@ + +.c.o: + ${PEASOUP_HOME}/tools/ps_comp.sh $< + +.cpp.o: + ${PEASOUP_HOME}/tools/ps_comp++.sh $< + +chopzero: + @ if [ ! -f chopzero ]; then gcc chopzero.c -o chopzero -O3 ; fi + +$(exes): ${STRATA}/lib/x86_linux/libstrata.a + + + +env_check: + @echo checking env vars; \ + if [ "X${TOOLCHAIN}" = "X" ]; then \ + echo TOOLCHAIN environment variable should be set.; \ + exit -1;\ + elif [ "X${STRATA}" = "X" ]; then \ + echo STRATA environment variable should be set. ;\ + exit -1;\ + elif [ "X${SMPSA_HOME}" = "X" ]; then \ + echo SMPSA_HOME environment variable should be set.; \ + exit -1;\ + elif [ "X${PEASOUP_HOME}" = "X" ]; then \ + echo PEASOUP_HOME environment variable should be set.; \ + exit -1;\ + elif [ "X${STRATA_HOME}" = "X" ]; then \ + echo STRATA_HOME environment variable should be set.; \ + exit -1;\ + fi ; + + +clean: + rm -f *.o *.syms *.map chopzero hanoi hanoi_overrun hanoi_heap_overrun malloc block_copy print_ptr hanoi_stack_overrun dumbledore a.out memcpy hanoi_overrun_taintedenv dumbledore_cmd hanoi_overrun_tainted hello cmd_args_005 + rm -f *.exe *.dis *.data *.idb *.log *.ncexe *.annot *.readelf temp.* *.temp *.stratafied *.asm *.SMPobjdump *.id0 *.id1 *.til *.nam + rm -Rf concolic.files_* + rm -Rf peasoup_executable_directory.* + rm -f strata.log.* + rm -f *.sym + if [ ! "X" = "X"${PGUSER} ]; then sh ../tools/db/drop_my_tables.sh; sh ../tools/db/pdb_setup.sh; fi + +concclean: + rm -Rf concolic.files_* + rm strata.log.* diff --git a/c++_examples/hanoi++.cpp b/c++_examples/hanoi++.cpp new file mode 100644 index 000000000..1eb2beb44 --- /dev/null +++ b/c++_examples/hanoi++.cpp @@ -0,0 +1,60 @@ +#include <assert.h> +/* * The Towers Of Hanoi * C * Copyright (C) 1998 Amit Singh. All Rights Reserved. * * Tested with, ah well ... :) */ +#include <stdio.h> +#include <stdlib.h> +#include <limits.h> +#include <assert.h> +#include <iostream> + +using namespace std; + + +#define FROM 1 +#define TO 3 +#define USING 2 + +void dohanoi(int N, int from, int to, int p_using) +{ + static int count=0; + + assert(N<100); /* 100 would take a long time, and recurse really deeply, chnage this const if you want, but this'll avoid unintential segfaults */ + if (N > 0) + { + dohanoi(N-1, from, p_using, to); + dohanoi(N-1, p_using, to, from); + } +} + + +int main (int argc, char **argv) +{ + long int N; + long int i; + int j; + + if (argc != 2) + { + cerr<< "usage: " << argv[0] << " N"<<endl ; exit(1); + } + N = strtol(argv[1], (char **)NULL, 10); /* a bit of error checking, LONG_XXX should be there in limits.h */ + + if (N == LONG_MIN || N == LONG_MAX || N <= 0) + { + cerr << "illegal value for number of disks"<<endl; + exit(2); + } + + for(i=0;i<N;i++) + { + + + cout << "Hanoi " << i << " ... " << endl; + fflush(stdout); + dohanoi(N, FROM, TO, USING); + + cout << "Hanoi " << i << endl; + } + + exit(0); +} + diff --git a/c++_examples/newdel.cpp b/c++_examples/newdel.cpp new file mode 100644 index 000000000..06a73a140 --- /dev/null +++ b/c++_examples/newdel.cpp @@ -0,0 +1,78 @@ +#include <assert.h> +/* * The Towers Of Hanoi * C * Copyright (C) 1998 Amit Singh. All Rights Reserved. * * Tested with, ah well ... :) */ +#include <stdio.h> +#include <stdlib.h> +#include <limits.h> +#include <assert.h> +#include <iostream> + +using namespace std; + + +#define FROM 1 +#define TO 3 +#define USING 2 + + +class foo +{ + public: + + foo() {} + virtual ~foo() {} + + private: + + string data; +}; + + +void dohanoi(int N, int from, int to, int p_using) +{ + static int count=0; + + assert(N<100); /* 100 would take a long time, and recurse really deeply, chnage this const if you want, but this'll avoid unintential segfaults */ + if (N > 0) + { + char *allocp2=new char; + foo *allocp=new foo; + dohanoi(N-1, from, p_using, to); + delete allocp; + dohanoi(N-1, p_using, to, from); + delete allocp2; + } +} + + +int main (int argc, char **argv) +{ + long int N; + long int i; + int j; + + if (argc != 2) + { + cerr<< "usage: " << argv[0] << " N"<<endl ; exit(1); + } + N = strtol(argv[1], (char **)NULL, 10); /* a bit of error checking, LONG_XXX should be there in limits.h */ + + if (N == LONG_MIN || N == LONG_MAX || N <= 0) + { + cerr << "illegal value for number of disks"<<endl; + exit(2); + } + + for(i=0;i<N;i++) + { + + + cout << "Hanoi " << i << " ... " << endl; + fflush(stdout); + dohanoi(N, FROM, TO, USING); + + cout << "Hanoi " << i << endl; + } + + exit(0); +} + diff --git a/c++_examples/newdel_broke1.cpp b/c++_examples/newdel_broke1.cpp new file mode 100644 index 000000000..3d616a0a5 --- /dev/null +++ b/c++_examples/newdel_broke1.cpp @@ -0,0 +1,76 @@ +#include <assert.h> +/* * The Towers Of Hanoi * C * Copyright (C) 1998 Amit Singh. All Rights Reserved. * * Tested with, ah well ... :) */ +#include <stdio.h> +#include <stdlib.h> +#include <limits.h> +#include <assert.h> +#include <iostream> + +using namespace std; + + +#define FROM 1 +#define TO 3 +#define USING 2 + + +class foo +{ + public: + + foo() { cout<<"Constructing a foo\n"; } + virtual ~foo() { cout<<"Destructing a foo\n"; } + + private: + + string data; +}; + + +void dohanoi(int N, int from, int to, int p_using) +{ + static int count=0; + + assert(N<100); /* 100 would take a long time, and recurse really deeply, chnage this const if you want, but this'll avoid unintential segfaults */ + if (N > 0) + { + foo *allocp=new foo; + dohanoi(N-1, from, p_using, to); + dohanoi(N-1, p_using, to, from); + delete [] allocp; + } +} + + +int main (int argc, char **argv) +{ + long int N; + long int i; + int j; + + if (argc != 2) + { + cerr<< "usage: " << argv[0] << " N"<<endl ; exit(1); + } + N = strtol(argv[1], (char **)NULL, 10); /* a bit of error checking, LONG_XXX should be there in limits.h */ + + if (N == LONG_MIN || N == LONG_MAX || N <= 0) + { + cerr << "illegal value for number of disks"<<endl; + exit(2); + } + + for(i=0;i<N;i++) + { + + + cout << "Hanoi " << i << " ... " << endl; + fflush(stdout); + dohanoi(N, FROM, TO, USING); + + cout << "Hanoi " << i << endl; + } + + exit(0); +} + diff --git a/c++_examples/newdel_broke2.cpp b/c++_examples/newdel_broke2.cpp new file mode 100644 index 000000000..908cb4633 --- /dev/null +++ b/c++_examples/newdel_broke2.cpp @@ -0,0 +1,76 @@ +#include <assert.h> +/* * The Towers Of Hanoi * C * Copyright (C) 1998 Amit Singh. All Rights Reserved. * * Tested with, ah well ... :) */ +#include <stdio.h> +#include <stdlib.h> +#include <limits.h> +#include <assert.h> +#include <iostream> + +using namespace std; + + +#define FROM 1 +#define TO 3 +#define USING 2 + + +class foo +{ + public: + + foo() { cout<<"Constructing a foo"<<endl;} + virtual ~foo() { cout<<"Destructing a foo"<<endl;} + + private: + + string data; +}; + + +void dohanoi(int N, int from, int to, int p_using) +{ + static int count=0; + + assert(N<100); /* 100 would take a long time, and recurse really deeply, chnage this const if you want, but this'll avoid unintential segfaults */ + if (N > 0) + { + foo *allocp=new foo [2]; + dohanoi(N-1, from, p_using, to); + dohanoi(N-1, p_using, to, from); + delete allocp; + } +} + + +int main (int argc, char **argv) +{ + long int N; + long int i; + int j; + + if (argc != 2) + { + cerr<< "usage: " << argv[0] << " N"<<endl ; exit(1); + } + N = strtol(argv[1], (char **)NULL, 10); /* a bit of error checking, LONG_XXX should be there in limits.h */ + + if (N == LONG_MIN || N == LONG_MAX || N <= 0) + { + cerr << "illegal value for number of disks"<<endl; + exit(2); + } + + for(i=0;i<N;i++) + { + + + cout << "Hanoi " << i << " ... " << endl; + fflush(stdout); + dohanoi(N, FROM, TO, USING); + + cout << "Hanoi " << i << endl; + } + + exit(0); +} + diff --git a/c++_examples/newdel_broke3.cpp b/c++_examples/newdel_broke3.cpp new file mode 100644 index 000000000..4e1cb6626 --- /dev/null +++ b/c++_examples/newdel_broke3.cpp @@ -0,0 +1,76 @@ +#include <assert.h> +/* * The Towers Of Hanoi * C * Copyright (C) 1998 Amit Singh. All Rights Reserved. * * Tested with, ah well ... :) */ +#include <stdio.h> +#include <stdlib.h> +#include <limits.h> +#include <assert.h> +#include <iostream> + +using namespace std; + + +#define FROM 1 +#define TO 3 +#define USING 2 + + +class foo +{ + public: + + foo() { cout<<"Constructing a foo\n"; } + virtual ~foo() { cout<<"Destructing a foo\n"; } + + private: + + string data; +}; + + +void dohanoi(int N, int from, int to, int p_using) +{ + static int count=0; + + assert(N<100); /* 100 would take a long time, and recurse really deeply, chnage this const if you want, but this'll avoid unintential segfaults */ + if (N > 0) + { + foo *allocp=new foo; + dohanoi(N-1, from, p_using, to); + dohanoi(N-1, p_using, to, from); + free(allocp); + } +} + + +int main (int argc, char **argv) +{ + long int N; + long int i; + int j; + + if (argc != 2) + { + cerr<< "usage: " << argv[0] << " N"<<endl ; exit(1); + } + N = strtol(argv[1], (char **)NULL, 10); /* a bit of error checking, LONG_XXX should be there in limits.h */ + + if (N == LONG_MIN || N == LONG_MAX || N <= 0) + { + cerr << "illegal value for number of disks"<<endl; + exit(2); + } + + for(i=0;i<N;i++) + { + + + cout << "Hanoi " << i << " ... " << endl; + fflush(stdout); + dohanoi(N, FROM, TO, USING); + + cout << "Hanoi " << i << endl; + } + + exit(0); +} + diff --git a/c++_examples/newdel_broke4.cpp b/c++_examples/newdel_broke4.cpp new file mode 100644 index 000000000..6e55a261c --- /dev/null +++ b/c++_examples/newdel_broke4.cpp @@ -0,0 +1,76 @@ +#include <assert.h> +/* * The Towers Of Hanoi * C * Copyright (C) 1998 Amit Singh. All Rights Reserved. * * Tested with, ah well ... :) */ +#include <stdio.h> +#include <stdlib.h> +#include <limits.h> +#include <assert.h> +#include <iostream> + +using namespace std; + + +#define FROM 1 +#define TO 3 +#define USING 2 + + +class foo +{ + public: + + foo() { cout<<"Constructing a foo\n"; } + virtual ~foo() { cout<<"Destructing a foo\n"; } + + private: + + string data; +}; + + +void dohanoi(int N, int from, int to, int p_using) +{ + static int count=0; + + assert(N<100); /* 100 would take a long time, and recurse really deeply, chnage this const if you want, but this'll avoid unintential segfaults */ + if (N > 0) + { + foo *allocp=new foo [2]; + dohanoi(N-1, from, p_using, to); + dohanoi(N-1, p_using, to, from); + free(allocp); + } +} + + +int main (int argc, char **argv) +{ + long int N; + long int i; + int j; + + if (argc != 2) + { + cerr<< "usage: " << argv[0] << " N"<<endl ; exit(1); + } + N = strtol(argv[1], (char **)NULL, 10); /* a bit of error checking, LONG_XXX should be there in limits.h */ + + if (N == LONG_MIN || N == LONG_MAX || N <= 0) + { + cerr << "illegal value for number of disks"<<endl; + exit(2); + } + + for(i=0;i<N;i++) + { + + + cout << "Hanoi " << i << " ... " << endl; + fflush(stdout); + dohanoi(N, FROM, TO, USING); + + cout << "Hanoi " << i << endl; + } + + exit(0); +} + diff --git a/tools/db/drop_my_tables.sh b/tools/db/drop_my_tables.sh index a78a4fe0a..a8e55aa9f 100755 --- a/tools/db/drop_my_tables.sh +++ b/tools/db/drop_my_tables.sh @@ -16,9 +16,7 @@ othertables="variant_dependency variant_info file_info doip" for i in $insntables $addrtables $functables $othertables do - echo -------------------------------------------------------------------------- echo -n Dropping table $i..." " psql -t -q -c "drop table $i cascade;" echo Done. - echo -------------------------------------------------------------------------- done -- GitLab