Error in editor mode when compiling errors

Archives Forums/Blitz3D Bug Reports/Error in editor mode when compiling errors

Yue(Posted 2012) [#1]
;.lib "shell32.dll"
;SHGetSpecialFolderLocation%(hwnd%,folder%,pidl*)
;SHGetPathFromIDList%(pidl%,pszPath*)




Const MAX_PATH=260

Const CSIDL_PROGRAMS=2					;Program Groups Folder
Const CSIDL_PERSONAL=5					;Personal Documents Folder
Const CSIDL_FAVORITES=6					;Favorites Folder
Const CSIDL_STARTUP=7					;Startup Group Folder
Const CSIDL_RECENT=8					;Recently Used Documents Folder
Const CSIDL_SENDTO=9   					;Send To Folder
Const CSIDL_STARTMENU=11  				;Start Menu Folder
Const CSIDL_DESKTOPDIRECTORY=16  		;Desktop Folder
Const CSIDL_NETHOOD=19					;Network Neighborhood Folder
Const CSIDL_TEMPLATES=21				;Document Templates Folder
Const CSIDL_COMMON_STARTMENU=22			;Common Start Menu Folder
Const CSIDL_COMMON_PROGRAMS=23			;Common Program Groups Folder
Const CSIDL_COMMON_STARTUP=24			;Common Startup Group Folder
Const CSIDL_COMMON_DESKTOPDIRECTORY=25	;Common Desktop Folder
Const CSIDL_APPDATA=26					;Application Data Folder
Const CSIDL_PRINTHOOD=27				;Printers Folder
Const CSIDL_COMMON_FAVORITES=1			;Common Favorites Folder
Const CSIDL_INTERNET_CACHE=32			;Temp. Internet Files Folder
Const CSIDL_COOKIES=33					;Cookies Folder
Const CSIDL_HISTORY=34					;History Folder



AppTitle  GetSpecialFolderLocation(CSIDL_PERSONAL)


Function GetSpecialFolderLocation$(folder)
temp=CreateBank(4)
SHGetSpecialFolderLocation(0,folder,temp)
pidl=PeekInt(temp,0)
FreeBank temp
If Not pidl Return
temp=CreateBank(MAX_PATH)
SHGetPathFromIDList(pidl,temp)
s$=PeekString(temp,0)
FreeBank temp
Return s
End Function

Function PeekString$(bank,offset)
	l = PeekInt(bank,offset)
	s$ = ""
	For i = 0 To MAX_PATH
        s$ = s$ + Chr$(PeekByte(bank,offset+i))
	Next
	Return s$
End Function

WaitKey()






I run the program and it works fine.

error here:






GfK(Posted 2012) [#2]
Try:
For i = 0 to MAX_PATH - 1


i.e. if your bank is 260 bytes long, each byte offset is numbered 0-259.

Last edited 2012


Floyd(Posted 2012) [#3]
You are trying to read 261 bytes from a bank of size 260.

With Debug On the error is detected. With debug off there is no bounds checking. This will crash ( Memory Access Violation ) if PeekByte attempts to read memory which is not allocated to your program.

In your program byte 261 is outside the bank, but still allocated to your program. So by good luck it does not crash. But it should be doing:

For i = 0 To MAX_PATH-1


Yue(Posted 2012) [#4]
ho!, ok thanks.