ABWL example

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

#include <iostream.h>

#include <windows.h>

 

int

main(int, char **)

{

    int *ptr = new int[2];          //Allocate memory for 2 ints

    for (int i=0; i <= 2; i++) {    //Bug: manipulate 3 ints, not 2

        ptr[i] = i;

        cerr << "ptr[" << i << "] == " << ptr[i] << '\n';

    }

    delete[] ptr; //ABWL: due to write when i was 2

    return(0); 

}

(C) Copyright IBM Corporation 1992, 2010.