Page 1 of 1

FileSeek Bug 5.72

Posted: Sun Apr 26, 2020 12:43 pm
by Saki

Code: Select all

; 負のオフセットのバグ - Negative offset bug - Positive works - Also error in doku ?
file$ = GetTemporaryDirectory() + "日本の小花であるサキ"
file = CreateFile(#PB_Any , file$)
WriteString(file , "AAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD" , #PB_UTF8)
Debug FileSeek(file , Lof(file) -8 )     ; Give back 24 - OK - But Doku say - "This function returns no value !" 
Debug ReadString(file , #PB_UTF8 , 8)    ; Read last 8 chars = DDDDDDDD
Debug FileSeek(file , -8 , #PB_Relative) ; Move file pointer 8 chars to left at pos 24 - OK
Debug ReadString(file , #PB_UTF8 , 8)    ; Results also DDDDDDDD - But FileSeek say file pointer is moved to pos 24 - FALSE
Debug Loc(file)                          ; Loc say file pointer is not moved - FALSE
CloseFile(file)
DeleteFile(file$)
// Edit: Moved from "Bug Forum" to "General Discussion" (Kiffi)

Re: FileSeek Bug 5.72

Posted: Sun Apr 26, 2020 1:05 pm
by BarryG
This is not a bug. Your second FileSeek() is just going back to the start of "DDDDDDDD" again, because ReadString() on the line above it has taken the file pointer back to the end of "DDDDDDDD". You're forgetting that ReadString() changes the file pointer.

Further, the return value of FileSeek() doesn't mean anything, which is why the manual says "None" for it. Don't assume that it means the file pointer (which is why you're confused).

Re: FileSeek Bug 5.72

Posted: Sun Apr 26, 2020 1:18 pm
by Little John
This is the original code, slightly modified for clarity.
It does not show a bug here with PB 5.72 LTS x64 on Windows 10.

Code: Select all

file$ = GetTemporaryDirectory() + "temp.txt"
file = CreateFile(#PB_Any, file$)
WriteString(file, "AAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD", #PB_UTF8)
Debug "Lof(file) = " + Lof(file)
Debug ""

Debug "Test #1"
FileSeek(file, Lof(file)-8) 
Debug Loc(file)                        ; Gives back 24 - OK
Debug ReadString(file, #PB_UTF8, 8)    ; Read last 8 chars = DDDDDDDD
Debug Loc(file)                        ; Gives back 32 - OK
Debug ""

Debug "Test #2"
FileSeek(file, -8, #PB_Relative)
Debug Loc(file)                        ; Gives back 24 - OK
Debug ReadString(file, #PB_UTF8, 8)    ; Read last 8 chars = DDDDDDDD
Debug Loc(file)                        ; Gives back 32 - OK

CloseFile(file)
DeleteFile(file$)
PS: If you seriously want to report a bug, you should at least tell the PureBasic version and the operating system you used when you encountered it.