File: wrong3.cc

package info (click to toggle)
duma 2.5.21-11
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,460 kB
  • sloc: ansic: 5,512; cpp: 2,205; makefile: 441; javascript: 191; sh: 129
file content (27 lines) | stat: -rw-r--r-- 576 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#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;

}