wrong3.cc 576 B

123456789101112131415161718192021222324252627
  1. #include <noduma.h>
  2. #include <iostream>
  3. #include <dumapp.h>
  4. using namespace std;
  5. int main() {
  6. cout << "Hello world!" << endl;
  7. int* pI = new int;
  8. int j;
  9. cerr << "Now reading uninitialized memory" << endl;
  10. j = *pI+2;
  11. cerr << "Did you notice? (value was " << j << ") " << endl;
  12. delete pI;
  13. cerr << "(No memory leak here)" << endl;
  14. int* pJ;
  15. cerr << "Now writing to uninitialized pointer" << endl;
  16. *pJ = j;
  17. cerr << "Did you notice?" << endl;
  18. // valgrind reports 4, but that's ok
  19. cerr << "There should be 2 errors in this run" << endl;
  20. return 0;
  21. }