domen@wiener.crin.fr (Eric Domenjoud) (11/20/89)
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 ----------------------------------------------------------