FMWL example

//Note: The following example generates an FMWL message when you use minimal instrumentation.

#include <iostream.h>

#include <windows.h>

 

int

main(int, char **)

{

    int *ptr = new int[2];

    ptr[0] = 0;

    ptr[1] = 1;

    delete[] ptr;   //Bug: put here accidentally instead of after for() loop below

    for (int i=0; i < 2; i++) {

        ptr[i] *= i;

        cerr << "element #" << i << " is " << ptr[i] << '\n';

    }

    return(0); //FMWL: due to write to ptr after it was deleted

}

(C) Copyright IBM Corporation 1992, 2010.