#include <iostream>
usingnamespace std;
int main ()
{
int * a = newint[0];
int n = 0;
//a[n] = 2;
while (1){
cin >> a[n];
if (cin.fail())
{
cout << "failed!";
}
if (a[n] == -1) break;
n++;
int * tmp = newint[n];
for (int i = 0; i<n;i++)
tmp[i] = a[i];
delete [] a;
a = 0;
a = tmp;
}
for(int u = 0; u < n; u++)
cout << a[u] << ",";
cout << endl;
delete []a;
return 0;
}
It crashes with the following error:
*** Error in `./ptr': free(): invalid next size (fast): 0x0000000001af6010 ***
I'm using gcc as my compiler.
Here's an interesting bit, when I execute the application with valgrind it does not crash. valgrind gives me an all memory deallocated message, so that leaves me to think that there is no dereference data lingering out there.