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

Re: [MiNT] Question about memory under MagiC



On Saturday 22 Oct 2011 23:18:48 Jo Even Skarstein wrote:
> On Sat, 2011-10-22 at 23:06 +0200, Jean-François Lemaire wrote:
> > However, under MagiC (tested by someone else) it crashes ("Memory block
> > destroyed by user program" message from MagiC).
> 
> Your strcpy has overwritten the end of the allocated memory block.

Since when does MiNT with MP accepts writing past the end of the buffer? I 
know from experience that it does not.

> . Which
> compiler/libs are you using?

GCC 4.5.2, mintlib 0.59.1, gemlib 0.43.6.

> Does it work with strncpy?

Didn't try. I never use that function.

> How are you
> *sure* that the string fits in the allocated buffer?

char path[PATHSIZE] = {0};
size_t size = snprintf(path, sizeof path, "%s%s", string1, string2) + 1;

then size is passed to the function that does the Mxalloc'ing then strcpy() 
call.

> Maybe you can post
> the code?

Sure, but several functions are involved so it's not straightforward (but I 
certainly can upload the complete sources) and, anyway, the code is 100 % 
stable under MiNT with MP on.

Thanks for the answer.
JFL
-- 
Jean-François Lemaire