is there anything i should worry about when I pass a reference to a pointer like that ?
I am trying to use similar code and I am getting crazy error about malloc fail,
Any idea? i will post snippit of my actual code that does receive error on its own.
compiles fine but has run-time error
Code:
#include <string>
#include <iostream>
using namespace std;
void magic(int* &mpNext, string x)
{
int m = x.length();
int i, j;
mpNext = new int[m];
for(int i=0;i<m;++i )
mpNext[i] = 0;
i = 0;
j = mpNext[0] = -1;
while (i < m) {
while (j > -1 && x[i] != x[j])
j = mpNext[j];
mpNext[++i] = ++j;
}
}
int main()
{
int *T;
string hay;
while(cin >> hay)
{
magic(T,hay);
cout << "method ran well" << endl;
}
return 0;
}
input:
output:
Code:
method ran well
method ran well
a.out: malloc.c:3074: sYSMALLOc: Assertion `(old_top == (((mbinptr) (((char *) &((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct malloc_chunk, fd)))) && old_size == 0) || ((unsigned long) (old_size) >= (unsigned long)((((__builtin_offsetof (struct malloc_chunk, fd_nextsize))+((2 * (sizeof(size_t))) - 1)) & ~((2 * (sizeof(size_t))) - 1))) && ((old_top)->size & 0x1) && ((unsigned long)old_end & pagemask) == 0)' failed.
Aborted
I am able to print out method ran well but then gives me big malloc error