#include<iostream.h>

char a[10];
char *b;

int main(int argc, char **argv){

 // corretto (esiste a[0])
 cout << a[0]; 
 // buffer overrun (b non e' ancora stato inizializzato)
 cout << b[0];

 b = new char[100];

 for(int i=0;i<=100;i++)
  b[i]=i; // buffer overrun per i==100
 
 
}


void scambio(int *a, int *b){
 int *x;

 x=new int;

 *x=*a;
 *a=*b;
 *b=*x;
} // memory leak non ho disallocato x


char *read_line(){
 char temp[1000];

 cin.getline(temp,1000);

 return temp; // lingering pointer: temp viene distrutto
              // all'uscita della funzione
}

char *read_line_corretto(){
 char temp[1000];
 char *p;

 cin.getline(temp,1000);
 
 p=new char[strlen(temp)+1];

 strcpy(p,temp);

 return p; // corretto: non confondere con memory leak
}