Added testcases from 'duma' package

This commit is contained in:
Daniel Marjamäki 2019-03-18 06:58:12 +01:00
parent 794f65bac1
commit d1025ce76d
15 changed files with 668 additions and 0 deletions

View File

@ -0,0 +1,12 @@
#include <stdio.h>
int main() {
printf("Hello world!\n");
int* pI;
pI = (int*)malloc(sizeof(int));
printf("Let's leak a pointer to int\n");
*pI = 303;
return 0;
}

View File

@ -0,0 +1,15 @@
#include <noduma.h>
#include <iostream>
#include <dumapp.h>
using namespace std;
int main() {
cout << "Hello world!" << endl;
int* pI = new int;
cerr << "Let's leak a pointer to int" << endl;
*pI = 303;
return 0;
}

View File

@ -0,0 +1,20 @@
#include <stdio.h>
int main() {
printf("Hello world!\n");
int* pI;
pI = (int*)malloc(10*sizeof(int));
printf("Let's leak a pointer to an array of 10 ints\n");
int i=0;
for (i=0; i<9; i++) {
pI[i] = 303+i;
}
int j=0;
for (j=0; j<9; j++) {
if (pI[j] != 303+j) printf(" Something strange is happening...\n");
}
return 0;
}

View File

@ -0,0 +1,20 @@
#include <noduma.h>
#include <iostream>
#include <dumapp.h>
using namespace std;
int main() {
cout << "Hello world!" << endl;
int* pI = new int[10];
cerr << "Let's leak a pointer to an array of 10 ints" << endl;
for (int i=0; i<9; i++) {
pI[i] = 303+i;
}
for (int i=0; i<9; i++) {
if (pI[i] != 303+i) cerr << " Something strange is happening..." << endl;
}
return 0;
}

View File

@ -0,0 +1,367 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><title>Comparison of Free Memory Checkers</title>
<link rel="start" type="text/html" href="http://www.cs.utexas.edu/%7Ejpmartin/index.html">
<link rel="up" type="text/html" href="http://www.cs.utexas.edu/%7Ejpmartin/resources.html">
<link rel="icon" type="image/png" href="http://www.cs.utexas.edu/%7Ejpmartin/longhorn_icon.png">
<link rel="styleSheet" href="memCheckers-Dateien/jpstyle.css" title="default stylesheet">
<link rel="Alternate StyleSheet" href="memCheckers-Dateien/boringstyle.css" title="alternate
(old-fashioned) stylesheet"></head><body>
<h1><a class="title" href="http://www.cs.utexas.edu/%7Ejpmartin/index.html">Jean-Philippe Martin</a> |
<a class="title" href="http://www.cs.utexas.edu/%7Ejpmartin/resources.html">Resources</a> | Memory Checkers Comparison </h1>
<hr>
<p>
</p><h3>Memory Checkers</h3>
Memory checkers are debugging tools that help programmers find
improper use of pointers, typically memory leaks.
<p align="justify">
There are some freely available memory checkers. I ran a series of
very simple tests to determine what they can do. The <b>wrong</b>
series of tests contains code that makes pointer mistakes that are not
memory leaks, for example freeing a pointer twice, writing to
uninitialized memory or using delete instead of delete []. The
<b>leak</b> series of tests contains simple memory leaks,
i.e. pointers that are allocated but not released. The <b>ok</b>
series of tests contains programs that are correct and thus should not
cause the memory checker to output any alarm message.
</p>
<h3>C tests</h3>
(updated 3/10/2006)<p>
<table border="1">
<colgroup>
</colgroup><colgroup span="3">
</colgroup><colgroup span="2">
</colgroup><colgroup>
</colgroup><tbody><tr>
<th>Checker
</th><th><a class="title" href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/wrong1.c">wrong1.c</a>
</th><th><a class="title" href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/wrong3.c">wrong3.c</a>
</th><th><a class="title" href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/wrong6.c">wrong6.c</a>
</th><th><a class="title" href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/wrong7.c">wrong7.c</a>
</th><th><a class="title" href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/leak1.c">leak1.c</a>
</th><th><a class="title" href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/leak2.c">leak2.c</a>
</th><th><a class="title" href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/ok5.c">ok5.c </a>
</th></tr>
<tr align="center">
<td><a class="title" href="http://www.gnu.org/manual/glibc-2.2.5/html_node/Heap-Consistency-Checking.html">MALLOC_CHECK_</a>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkred">missed</font></b>
</td><td><b><font color="darkred">missed</font></b>
</td><td><b><font color="darkgreen">OK</font></b><a href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/wrong7.out">*</a>
</td><td><b><font color="darkred">missed</font></b>
</td><td><b><font color="darkred">missed</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td></tr>
<tr align="center">
<td><a class="title" href="http://dmalloc.com/">dmalloc</a>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkred">missed</font></b>
</td><td><b><font color="darkred">missed</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td></tr>
<tr align="center">
<td><a class="title" href="http://prj.softpixel.com/mcd/">memCheckDeluxe</a>
</td><td><b><font color="darkred">missed</font></b>
</td><td><b><font color="darkred">missed</font></b>
</td><td><b><font color="darkred">missed</font></b>
</td><td><b><font color="darkred">missed</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td></tr>
<tr align="center">
<td><a class="title" href="http://www.linkdata.se/sourcecode.html">memwatch</a>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkred">missed</font></b>
</td><td><b><font color="darkred">missed</font></b><a href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/memwatch-response.txt">*</a>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td></tr>
<tr align="center">
<td><a class="title" href="http://duma.sourceforge.net/">DUMA</a>
</td><td><b><font color="darkgreen">OK</font></b>
<!-- segfaults on the bad write, but misses the bad read -->
</td><td><b><font color="darkred">missed</font></b>
</td><td><b><font color="darkred">missed</font></b>
<!-- segfaults on the first bug. That counts as finding it -->
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkgreen">OK<a href="http://www.cs.utexas.edu/%7Ejpmartin/duma-l2c.txt">*</a></font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td></tr>
<tr align="center">
<td><a class="title" href="http://devel-home.kde.org/%7Esewardj/">valgrind</a>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkred">missed</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td></tr>
</tbody></table>
</p><p>
</p><h3>C++ tests</h3>
<table border="1">
<tbody><tr>
<th>Checker
</th><th><a class="title" href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/wrong1.cc">wrong1.cc</a>
</th><th><a class="title" href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/wrong2.cc">wrong2.cc</a>
</th><th><a class="title" href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/wrong3.cc">wrong3.cc</a>
</th><th><a class="title" href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/wrong4.cc">wrong4.cc</a>
</th><th><a class="title" href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/wrong5.cc">wrong5.cc</a>
</th><th><a class="title" href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/wrong6.cc">wrong6.cc</a>
</th><th><a class="title" href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/leak1.cc">leak1.cc</a>
</th><th><a class="title" href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/leak2.cc">leak2.cc</a>
</th><th><a class="title" href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/ok5.cc">ok5.cc</a>
</th></tr>
<tr align="center">
<td><a class="title" href="http://www.gnu.org/manual/glibc-2.2.5/html_node/Heap-Consistency-Checking.html">MALLOC_CHECK_</a>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkred">missed</font></b>
</td><td><b><font color="darkred">missed</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkred">missed</font></b>
</td><td><b><font color="darkred">missed</font></b>
</td><td><b><font color="darkred">missed</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td></tr>
<tr align="center">
<td><a class="title" href="http://dmalloc.com/">dmalloc</a>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkgreen">OK</font><a href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/dmalloc-wrong2.txt">*</a></b>
</td><td><b><font color="darkred">missed</font><a href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/dmalloc-wrong3.txt">*</a></b>
</td><td><b><font color="darkred">missed</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkred">missed</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkred">missed</font><a href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/dmalloc-ok5.txt">*</a></b>
</td></tr>
<tr align="center">
<td><a class="title" href="http://duma.sourceforge.net/">DUMA</a>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
<!-- caught the write to uninitialized memory, but not the read -->
</td><td><b><font color="darkred">missed</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkred">missed</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkred">missed</font></b>
</td></tr>
<tr align="center">
<td><a class="title" href="http://devel-home.kde.org/%7Esewardj/">valgrind</a>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkgreen">OK<a href="http://www.cs.utexas.edu/%7Ejpmartin/valgrind-w3cc.txt">*</a></font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkred">missed</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td></tr>
</tbody></table>
<p>
</p><h3>Conclusion</h3>
<p align="justify">
memWatch and memCheckDeluxe are both memory leak detectors, and they
passed all the memory leak tests. Memwatch wins this round because it
was able to detect the double-free in wrong1.c and the out-of-bounds
accesses in the dynamically allocated array of wrong7.c (not the
static array of wrong6 - but no one else did, either).
Both programs are designed to work with C and require a
recompilation.
</p>
<p align="justify">
MALLOC_CHECK_ is an interesting test: it is triggered simply by
setting the environment variable MALLOC_CHECK_ to 1, and the rest of
the magic is done by glibc (see the link in references, below). This
is the easiest check to set up and it requires no recompilation. It
detected the double free in wrong1 and the mismatched malloc/delete or
new/free pairs in wrong2.cc and wrong5.cc. It was able to see that
something was fishy in wrong7.c, but it reports a single error at the "free"
instead of when we are accessing the memory instead of two errors, for
each out-of-bounds access. MALLOC_CHECK_ cannot detect
memory leaks and did not detect the use of uninitialized memory in
wrong3.
</p>
<p align="justify">
dmalloc is more than a leak detector, but it didn't detect as
many bad cases as valgrind and requires a recompile. Also, its C++
support is (in the author's words) minimal. In particular, I have not
been able to get dmalloc to report line numbers with C++ (<a href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/dmalloc-cpp.txt">log</a>), although that feature mostly
works with C code - in both leak1.c and leak2.c it pointed to
the <tt>return()</tt> instead of the line that allocated the unfreed
memory. Dmalloc also often reports unfreed memory, even for programs
that are correct. This may be because of errors in the c++ library,
but it makes the reports harder to read. In contrast, valgrind has a
way to hide leaks that it knows about so its reports are more
clear. See also the <a href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/dmalloc-feedback.txt">author's comments</a>.
</p>
<p align="justify">
valgrind is clearly the winner of this little contest. valgrind
requires no recompilation of the program, so it's very easy to set
up. It identified almost all of the incorrect pointer uses and memory
leaks. The only test that it missed is wrong6, in which we break the
bounds of an array. No other checker spotted that one, though. Also,
valgrind has been improved since we ran this test, so it may perform
even better than what we show here.
</p>
<p align="justify">
DUMA is a very close second. The results I am posting here come from
Koneru Srikanth (kpsrikanth at gmail dot com) who generously sent them
to me. DUMA seems not to require a recompile, but the tests were run
on recompiled code. DUMA performs really well. It was also able to
detect out-of-bounds writes
(it is reported as failing wrong3.cc because it missed the
out-of-bounds read). If for some reason valgrind does not work for
you, then I recommend that you give DUMA a spin.
</p><h3>Reference</h3>
I tested:
<ul>
<li><a href="http://www.gnu.org/manual/glibc-2.2.5/html_node/Heap-Consistency-Checking.html">MALLOC_CHECK_</a>
for glibc (C and C++: requires no recompilation)
</li><li><a href="http://dmalloc.com/">dmalloc-5.2.2</a> (C, minimal C++ support; requires recompilation)
</li><li><a href="http://prj.softpixel.com/mcd/">memCheckDeluxe-1.2.2</a> (C,
some C++. Requires recompilation)
</li><li><a href="http://www.linkdata.se/sourcecode.html">memwatch-2.71</a> (C
only; requires recompilation)
</li><li><a href="http://devel-home.kde.org/%7Esewardj/">valgrind-1.9.6</a>
(C, C++ and more: requires no recompilation)
</li><li><a href="http://duma.sourceforge.net/">DUMA</a> version 2.4.26
(C and C++. Documentation says that no recompilation is needed, but
the tests were run on recompiled code) (as mentioned above, these tests
were contributed by Koneru Srikanth).
</li></ul>
I did not test:
<ul>
<li><a href="http://perens.com/FreeSoftware/">electric fence-2.1</a>
(did not compile on first attempt (<a href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/efence-output.txt">log</a>))
</li><li><a href="http://check.sourceforge.net/">Checker-0.9.9.1</a> (did
not compile on first attempt (<a href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/checker-output.txt">log</a>); author suggests I use
valgrind instead)
</li></ul>
Test programs:
<ul>
<li><a href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/wrong1.c">wrong1.c</a>
</li><li><a href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/wrong3.c">wrong3.c</a>
</li><li><a href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/wrong6.c">wrong6.c</a>
</li><li><a href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/wrong7.c">wrong7.c</a>
</li><li><a href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/leak1.c">leak1.c</a>
</li><li><a href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/leak2.c">leak2.c</a>
</li><li><a href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/ok5.c">ok5.c </a>
</li><li><a href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/wrong1.cc">wrong1.cc</a>
</li><li><a href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/wrong2.cc">wrong2.cc</a>
</li><li><a href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/wrong3.cc">wrong3.cc</a>
</li><li><a href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/wrong4.cc">wrong4.cc</a>
</li><li><a href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/wrong5.cc">wrong5.cc</a>
</li><li><a href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/wrong6.cc">wrong6.cc</a>
</li><li><a href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/leak1.cc">leak1.cc</a>
</li><li><a href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/leak2.cc">leak2.cc</a>
</li><li><a href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/ok5.cc">ok5.cc</a>
</li></ul>
<h3>ToDo</h3>
The following memory checkers have been mentionned to me but I haven't
tried them yet:
<ul>
<li>mpatrol at http://www.cbmamiga.demon.co.uk/mpatrol/
</li></ul>
<h3>Change History</h3>
March 10, 2006: added DUMA, contributed by Koneru Srikanth
<br>
Oct 6, 2003: mention of mpatrol
<br>
Sept 29, 2003: added dmalloc
<br>
June 25, 2003: minor change in the text
<br>
June 24, 2003: corrected result for memwatch's wrong1.c, added wrong7.c
<br>
June 15, 2003: initial release
<p>
Please <a href="http://www.cs.utexas.edu/%7Ejpmartin/contact.html">contact</a> me if you have feedback or
would like to suggest another tool for the test.
</p><p></p><hr>
[<a accesskey="j" href="http://www.cs.utexas.edu/%7Ejpmartin/index.html"><b>J</b>P Martin</a>]
[<a accesskey="s" href="http://www.cs.utexas.edu/%7Ejpmartin/resources.html">re<b>s</b>ources</a>]
[<a accesskey="c" href="http://www.cs.utexas.edu/%7Ejpmartin/contact.html"><b>c</b>ontact information</a>]
<p>
</p><center>
<a href="http://www.anybrowser.org/campaign/"><img src="memCheckers-Dateien/viewed-any.gif" alt="Best viewed with *any* browser" border="0" height="30" width="85"></a>
</center>
</body></html>

View File

@ -0,0 +1,13 @@
#include <stdio.h>
int main() {
printf("Hello world!\n");
int* pI = (int*)malloc(sizeof(int));
*pI=2;
free(pI);
printf("Now freeing a pointer twice...\n");
free(pI);
printf("Did you notice?\n");
return 0;
}

View File

@ -0,0 +1,16 @@
#include <noduma.h>
#include <iostream>
#include <dumapp.h>
using namespace std;
int main() {
cout << "Hello world!" << endl;
int* pI = new int;
*pI=2;
delete(pI);
cerr << "Now deleting a pointer twice..." << endl;
delete(pI);
cerr << "Did you notice?" << endl;
return 0;
}

View File

@ -0,0 +1,25 @@
#include <noduma.h>
#include <iostream>
#include <dumapp.h>
using namespace std;
int main() {
cout << "Hello world!" << endl;
int* pI = new int;
*pI=2;
cerr << "Now freeing a pointer instead of deleting it..." << endl;
free(pI);
cerr << "Did you notice?" << endl;
pI = new int;
delete(pI);
cerr << "Now deleting twice..." << endl;
delete(pI);
cerr << "Did you notice?" << endl;
cerr << "There should be 2 errors in this run" << endl;
return 0;
}

View File

@ -0,0 +1,22 @@
#include <stdio.h>
int main() {
printf("Hello world!\n");
int* pI = (int*)malloc(sizeof(int));
int j;
printf("Now reading uninitialized memory\n");
j = *pI+2;
printf("Did you notice? (value was %i)\n",j);
free(pI);
printf("(No memory leak here)\n");
int* pJ;
printf("Now writing to uninitialized pointer\n");
*pJ = j;
printf("Did you notice?\n");
// valgrind reports 8, but that's ok
printf("There should be 2 errors in this run\n");
return 0;
}

View File

@ -0,0 +1,26 @@
#include <noduma.h>
#include <iostream>
#include <dumapp.h>
using namespace std;
int main() {
cout << "Hello world!" << endl;
int* pI = new int;
int j;
cerr << "Now reading uninitialized memory" << endl;
j = *pI+2;
cerr << "Did you notice? (value was " << j << ") " << endl;
delete pI;
cerr << "(No memory leak here)" << endl;
int* pJ;
cerr << "Now writing to uninitialized pointer" << endl;
*pJ = j;
cerr << "Did you notice?" << endl;
// valgrind reports 4, but that's ok
cerr << "There should be 2 errors in this run" << endl;
return 0;
}

View File

@ -0,0 +1,26 @@
#include <noduma.h>
#include <iostream>
#include <dumapp.h>
using namespace std;
int main() {
cout << "Hello world!" << endl;
{
int* pI = new int[10];
cerr << "Let's delete instead of delete [] " << endl;
delete pI;
cerr << "Did you notice?" << endl;
}
{
int* pI = new int[10];
cerr << "Now let's free instead of delete [] " << endl;
free(pI);
cerr << "Did you notice?" << endl;
}
cerr << "There should be 2 errors in this run" << endl;
return 0;
}

View File

@ -0,0 +1,39 @@
#include <noduma.h>
#include <iostream>
#include <string>
#include <dumapp.h>
using namespace std;
class Test {
public:
int a;
string stdstr;
Test() {
a=2;
stdstr = "test";
}
};
int main() {
cout << "Hello world!" << endl;
{
Test* pI = new Test[10];
cerr << "Let's delete instead of delete [] " << endl;
delete pI;
cerr << "Did you notice?" << endl;
}
{
Test* pI = new Test[10];
cerr << "Now let's free instead of delete [] " << endl;
free(pI);
cerr << "Did you notice?" << endl;
}
cerr << "There should be 2 errors in this run" << endl;
return 0;
}

View File

@ -0,0 +1,19 @@
#include <stdio.h>
struct Test {
int a;
char st[10];
};
int main() {
printf("Hello world!\n");
struct Test ar[10];
struct Test b;
printf("Let's index out of bounds \n");
ar[10].a=10;
printf("Did you notice?\n");
printf("There should be 1 error in this run\n");
return 0;
}

View File

@ -0,0 +1,35 @@
#include <noduma.h>
#include <iostream>
#include <string>
#include <dumapp.h>
using namespace std;
class Test {
public:
int a;
string stdstr;
Test() {
a=2;
stdstr = "test";
}
void doNothing() {
cout << " hi!" << endl;
};
};
int main() {
cout << "Hello world!" << endl;
Test ar[10];
Test b;
cerr << "Let's index out of bounds " << endl;
ar[10].doNothing();
cerr << "Did you notice?" << endl;
cerr << "There should be 1 error in this run" << endl;
return 0;
}

View File

@ -0,0 +1,13 @@
#include <stdio.h>
int main() {
int *p;
p = (int*) malloc( sizeof(int) * 10 );
printf("Now writing before our allocated array\n");
p[-1] ^= 0x0F; /* bash before */
printf("... and now after our allocated array\n");
p[10] ^= 0x0F; /* bash after */
printf("Did you notice?\n");
free(p);
}