Re: strange Seg fault



Hi,

Marco Lettere <lettere di unipi it> writes:

> you are trying to write something to non allocated memory.
> *t[3] is an array of pointers which are not initialized and could point
> anywhere. when you make a sprintf on t[0] you are  writing somewhere you
> don't expect. Actually you're overwriting the stack so the ghost variable
> is overwritten and you're save. w/o the ghost variable you're done. :)
> try to declare t as gchar *t[3][MAX_STR_LEN], otherwise allocate memory
> with a malloc t[0] = (gchar*)malloc(MAX_STR_LEN); this should work.

better use g_strdup_printf(), _never_ use sprintf().


Salut, Sven



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]