[hatari-devel] Sign of Fread size parameter (was: Wotanoid problem)

Thomas Huth huth at users.berlios.de
Mon Jan 25 21:44:31 CET 2010


On Mon, 25 Jan 2010 22:10:49 +0200
Eero Tamminen <eerot at users.berlios.de> wrote:

> On Monday 25 January 2010, LAURENT SALLAFRANQUE wrote:
> > After that Georges reported that the files open under falcon with
> > $ffffffff, I've written the patch diferently.
> >
> > I've separated the Falcon and St management.
> > (This patch is just for the example, it can be cleaned before being
> > commited).
> >
> > Do you think this way is better ?
> 
> George just tested that the change was between STE (TOS 1.6 I assume)
> and Falcon (TOS 4.x I assume).  The change may still have happened in
> TOS 2 or TOS 3.  And besides, one can also use EmuTOS with Falcon and
> that uses signed value. :-)

I just wrote a little test program (am I the only one here with a
working cross-compiler?), that simply executes an Fopen + Fread with
size 0xffffffff, and it seems like the Fread size parameter is still
signed in TOS 2.06 and TOS 3.06, but has become unsigned with TOS 4.00.

> Thomas, I think it would be fairly safe to change the value to
> unsigned. There can't be many programs that rely on operating system
> calls like this to *fail* when given parameters that are invalid in
> older TOS versions.

Well, but some old programs might rely on this behaviour - especially
since the parameter is documented as signed in all major documentation.

I suggest the following fix: Make the Size variable unsigned (e.g.
Uint32), and add something like the following code right after the
Gemdos_IsInvalidFileHandle() check in gemdos.c:

	/* Old TOS versions treat the Size parameter as signed */
	if (TosVersion < 0x400 && (Size & 0x80000000))
	{
		/* return -1 as original GEMDOS */
		Regs[REG_D0] = -1;
		return true;
	}

What do you think?

> I would still like it to be pinpointed more accurately in which exact
> TOS version this behaviour change happened so that we can document it
> (at least in the source code).

I've also put Gerhard Stoll on CC:, he's the maintainer of the TOS
hypertext, so it might be interesting for him, too.

 Thomas



More information about the hatari-devel mailing list