Re: [hatari-devel] Possible bug in GEMDOS emulation: Failing write causes subsequent reads to fail

[ Thread Index | Date Index | More lists.tuxfamily.org/hatari-devel Archives ]


This is a multi-part message in MIME format.
Hi Christian,

Thanks for reporting!

Looking at the ferror() man page, errors indeed
require clearerr() call.

Does the attached (compile tested) patch look OK /
fix it?


	- Eero

On 1/8/21 10:11 PM, Christian Zietz wrote:
Hello,

consider the minimal example below, which opens a file in read-only
mode. It's acceptable that Fwrite fails -- even though at least some
Atari GEMDOS versions do not check the Fopen mode here and let the
Fwrite succeed.

However, under Hatari's GEMDOS emulation, the following Fread() also
fails, which is a bug, imho. I get the following trace output from Hatari:

GEMDOS 0x40 Fwrite(64, 16, 0x2e94c) at PC 0x12956
WARN : GEMDOS failed to write to '[...]'
-> ERROR (errno = 9)

... and then...

GEMDOS 0x3F Fread(64, 16, 0x2e94c) at PC 0x1296E
WARN : GEMDOS failed to read from '[...]': No error
-> ERROR (errno = 0)

... which causes Fread to return -1. Note how it says "failed [...] no
error [...] errno = 0". Possibly this is because Hatari relies on ferror():
https://git.tuxfamily.org/hatari/hatari.git/tree/src/gemdos.c#n2335
... but never clears the error flag with clearerr().

Regards
Christian

/* --- BEGIN EXAMPLE --- */
#include <osbind.h>
#include <stdio.h>

char buf[16];

int main(void)
{
         long res, h;
         res = Fopen("existing.txt", 0); /* open read-only */
         printf("Fopen: %ld\r\n", res);
         h = res;
         res = Fwrite(h, sizeof(buf), buf); /* might fail */
         printf("Fwrite: %ld\r\n", res);
         res = Fread(h, sizeof(buf), buf); /* expected to succeed */
         printf("Fread: %ld\r\n", res);
         Fclose(h);
         return 0;
}
/* --- END EXAMPLE --- */
--
Christian Zietz  -  CHZ-Soft  -  czietz@xxxxxxx
WWW: https://www.chzsoft.de/
PGP/GnuPG-Key-ID: 0x52CB97F66DA025CA / 0x6DA025CA








Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/