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

Re: [MiNT] USERDEF stack size



Vincent Rivière a écrit :
An alternative would be to use alloca(), to allocate a buffer on the stack using the exact size.

For test purpose, I have fixed v_gtext() and vqt_extent() with alloca(), it is enough to fix the QED info box, at least with the TOS 1.62.

	short *vdi_intin = alloca (sizeof (short) * strlen (str));

As people said, the strings are usually quite short, so if we keep fingers crossed it will not overflow...

malloc() is slower, but the only safe solution.

But I saw other problematic functions:

short
vst_name (short handle, short font_format, char *font_name, char *ret_name)
{
	short vdi_control[VDI_CNTRLMAX];
	short vdi_intin[VDI_INTINMAX];
	short vdi_intout[VDI_INTOUTMAX];
...

In the case of intin, we can know the ideal size, but for intout we can't guess the string size :-(
Once again, the only reliable solution is to call malloc() with
VDI_INTOUTMAX.

It is obvious that the VDI has been (badly) designed to use global arrays, using local arrays is a headacke, especially combined with USERDEFs and their small stack size.

I wonder if the right hack would not be to switch to restore USP and switch to user mode before calling the USERDEFs callbacks...

--
Vincent Rivière