FileSeek Bug 5.72

Everything else that doesn't fall into one of the other PB categories.
User avatar
Saki
Addict
Addict
Posts: 830
Joined: Sun Apr 05, 2020 11:28 am
Location: Pandora

FileSeek Bug 5.72

Post 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)
地球上の平和
BarryG
Addict
Addict
Posts: 3294
Joined: Thu Apr 18, 2019 8:17 am

Re: FileSeek Bug 5.72

Post 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).
Little John
Addict
Addict
Posts: 4519
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: FileSeek Bug 5.72

Post 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.
Post Reply