🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.atari.st
Article #5924

BUG in FWRITE (LATTICE C)

#5924
From: Eric Domenjoud
Date: Mon, 20 Nov 1989 09:19
85 lines
2372 bytes
I'd like to report a bug I found in the function FWRITE of the library
GEMLIB.BIN of LATTICE C. Writing 0xFF to a file causes an error.
I've included the code of this function with some comments so that 
everybody can see the bug is.

Did somebody already notice it? 
Does this bug really exist or only in my version ? (would be very strange)

Anyway, be carefull when using this function.

	Eric

----------------------------------------------

FHANDLE	= 20	; file handle
BLKCNT	= 16	; number of blocks to be written
BLKSIZE	= 12	; block size
BADDR	=  8	; address of the current byte

BLKWR	= -4	; blocks written
BYTEWR	= -8	; bytes written
THEBYTE = -12	; current byte


FWRITE:
	link	A6,#-12
	clr.l	-4(A6)		; no block written
	
NEXTBLK:
	move.l	-4(A6),D0
	cmp.l	16(A6),D0
	bge.s	ALLDONE
	clr.l	-8(A6)		; no byte written

NEXTBYTE:
	move.l	-8(A6),D0
	cmp.l	12(A6),D0
	bge.s	BLKDONE
	movea.l	8(A6),A0	; If the byte to be written is 0xFF
	move.b	(A0),D0		; D0 = 0xFF
	ext.w	D0		; D0 = 0xFFFF
	ext.l	D0		; D0 = 0xFFFFFFFF
	addq.l	#1,8(A6)
	movea.l	20(A6),A0
	move.l	8(A0),D1
	subq.l	#1,D1
	move.l	D1,8(A0)
	move.l	D0,-12(A6)
	tst.l	D1
	bmi.s	BUFFULL		; branch if the file buffer is full
	movea.l	(A0),A1		; Otherwise ...
	addq.l	#1,(A0)
	move.b	D0,(A1)		; D0 still contains 0xFFFFFFFF
	ext.w	D0		; 
	ext.l	D0		;
	bra.s	ONEDONE		; LOOK ... 
				   |
BUFFULL:			   |
	move.l	20(A6),-(SP)	   |
	move.l	-12(A6),-(SP)	   |
	jsr	_FLSBF		   |
	addq.l	#8,SP		   |
				   |
ONEDONE:			   V
	addq.l	#1,D0		; D0 now contains 0 !
	bne.s	NOERROR		; and we have an error !!!!!
	move.l	-4(A6),D0
	unlk	A6
	rts

NOERROR:
	addq.l	#1,-8(A6)
	bra.s	NEXTBYTE

BLKDONE:
	addq.l	#1,-4(A6)
	bra.s	NEXTBLK

ALLDONE:
	move.l	-4(A6),D0
	unlk	A6
	rts

----------------------------------------------------------	
Technical Details
Message-ID: <926@loria.crin.fr>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!iuvax!cica!ctrsol!emory!cambridge.apple.com!bloom-beacon!eru!luth!sunic!mcsun!inria!loria!wiener.crin.fr!domen

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!iuvax!cica!ctrsol!emory!cambridge.apple.com!bloom-beacon!eru!luth!sunic!mcsun!inria!loria!wiener.crin.fr!domen
From: domen@wiener.crin.fr (Eric Domenjoud)
Newsgroups: comp.sys.atari.st
Subject: BUG in FWRITE (LATTICE C)
Keywords: LATTICE C, GEMLIB.BIN, FWRITE
Message-ID: <926@loria.crin.fr>
Date: 20 Nov 89 09:19:50 GMT
Sender: news@loria.crin.fr
Reply-To: domen@loria.crin.fr (Eric Domenjoud)
Organization: CRIN, Nancy, France
Lines: 85