Two bugs: ReadAvail & Banks

Archives Forums/BlitzPlus Bug Reports/Two bugs: ReadAvail & Banks

FS(Posted 2011) [#1]
I think to have found two bugs in BlitzPlus with the following function:
Function mysql_get_packet(conn.mysqlConn)
 If Eof(conn\stream) Then RuntimeError "EOF"
 If ReadAvail(conn\stream) = 0 Then  ;wait for a packet (the secound packet seems to arrive immediately)
  Local timer = CreateTimer(10)
   Repeat
     WaitTimer timer
   Until ReadAvail(conn\stream)
   FreeTimer timer
 EndIf
 Local head = ReadInt(conn\stream)  ;packet-header
 Local size = head And $00FFFFFF
 Local no   = convertInt(head And $FF000000)
 Local result = CreateBank(size)
 ReadBytes result, conn\stream, 0, size
 DebugLog "got a packet ("+size+" bytes)"
 If size = 0 Then       ;result is an empty bank (BankSize(result) = 0) BUT THIS WORKS!!!!!!!!
   DebugLog "First byte of packet: "+PeekByte(result, 0)
 EndIf
 If ReadAvail(conn\stream) <> 0 Then       ;this condition should not be true if the packet-header is correct
   DebugLog "there is still some read avail ("+ReadAvail(conn\stream)+" bytes)"
   Local ra = ReadAvail(conn\stream)
   For i=1 To ra         ;The loop While ReadAvail(conn\stream) never finishes!
     DebugLog ReadByte(conn\stream) 
     DebugLog ReadAvail(conn\stream)+" bytes left"   ;allways the same
   Next
 Else
   DebugLog "There is no read avail any more."
 EndIf
 Return result
End Function


The first packet arrives perfectly. By trying to receive the secound one, ReadAvail returns 31, but I get a size of 0. But I can read
some Bytes of the (empty?) bank "result". After reading some bytes with ReadByte(s) off the stream, the return value of ReadAvail keeps
to be 31. I cannot explain both of these two problems, so I think them to be bugs.

Last edited 2011


Yasha(Posted 2011) [#2]
No opinion on ReadAvail, but being able to read from an empty bank is normal enough. The program doesn't seem to check the requested index against the size of the bank unless you're in Debug mode, presumably for better performance. You're just accessing undefined memory. (The idea is to treat this as an error in your program logic, and remove it by testing in Debug mode before you finalize the code. After all, it would still break the program if Blitz did detect it!)


FS(Posted 2011) [#3]
Thanks for your reply.
But ReadAvail is the real problem - I have to know, whether a packet has arrived or I have to wait for it.