PlanetSquires Forums

Support Forums => General Board => Topic started by: Bumblebee on November 25, 2023, 05:11:10 AM

Title: Testing the 'bad subscript' error - did not expect this
Post by: Bumblebee on November 25, 2023, 05:11:10 AM
dim b(1 to 5) as string
print lbound(b)
print ubound(b)
print "Press any key to continue..."
sleep
print b(8)
print "Press any key to quit"
sleep
end
Instead of a program crash, generates some gibberish, then runs the next lines of code.

Compiler log file:
Successful Compile (Errors 0 Warnings 0)

Primary Source: C:\ProgramData\WinFBE\FreeBASIC-1.07.2-gcc-5.2\Untitled1.bas
Target Compilation: C:\ProgramData\WinFBE\FreeBASIC-1.07.2-gcc-5.2\Untitled1.exe (29 KB, 29696 bytes)
Compile Time: 0.0 seconds (2023-11-25 09:04:03)

Command Line:
C:\ProgramData\WinFBE\FreeBASIC-1.07.2-gcc-5.2\fbc32.exe -m "C:\ProgramData\WinFBE\FreeBASIC-1.07.2-gcc-5.2\Untitled1.bas" -v -s console  -x "C:\ProgramData\WinFBE\FreeBASIC-1.07.2-gcc-5.2\Untitled1.exe"

FreeBASIC Compiler - Version 1.07.2 (2020-12-25), built for win32 (32bit)
Copyright (C) 2004-2019 The FreeBASIC development team.
standalone
target:       win32, 486, 32bit
compiling:    C:\ProgramData\WinFBE\FreeBASIC-1.07.2-gcc-5.2\Untitled1.bas -o C:\ProgramData\WinFBE\FreeBASIC-1.07.2-gcc-5.2\Untitled1.asm (main module)
assembling:   C:\ProgramData\WinFBE\FreeBASIC-1.07.2-gcc-5.2\bin\win32\as.exe --32 --strip-local-absolute "C:\ProgramData\WinFBE\FreeBASIC-1.07.2-gcc-5.2\Untitled1.asm" -o "C:\ProgramData\WinFBE\FreeBASIC-1.07.2-gcc-5.2\Untitled1.o"
linking:      C:\ProgramData\WinFBE\FreeBASIC-1.07.2-gcc-5.2\bin\win32\ld.exe -m i386pe -o "C:\ProgramData\WinFBE\FreeBASIC-1.07.2-gcc-5.2\Untitled1.exe" -subsystem console "C:\ProgramData\WinFBE\FreeBASIC-1.07.2-gcc-5.2\lib\win32\fbextra.x" --stack 1048576,1048576 -s -L "C:\ProgramData\WinFBE\FreeBASIC-1.07.2-gcc-5.2\lib\win32" -L "." "C:\ProgramData\WinFBE\FreeBASIC-1.07.2-gcc-5.2\lib\win32\crt2.o" "C:\ProgramData\WinFBE\FreeBASIC-1.07.2-gcc-5.2\lib\win32\crtbegin.o" "C:\ProgramData\WinFBE\FreeBASIC-1.07.2-gcc-5.2\lib\win32\fbrt0.o" "C:\ProgramData\WinFBE\FreeBASIC-1.07.2-gcc-5.2\Untitled1.o" "-(" -lfb -lgcc -lmsvcrt -lkernel32 -luser32 -lmingw32 -lmingwex -lmoldname -lgcc_eh "-)" "C:\ProgramData\WinFBE\FreeBASIC-1.07.2-gcc-5.2\lib\win32\crtend.o"
Title: Re: Testing the 'bad subscript' error - did not expect this
Post by: Bumblebee on November 25, 2023, 05:17:30 AM
Print b(32) is more interesting - partial gibberish followed by a crash  ;D
Title: Re: Testing the 'bad subscript' error - did not expect this
Post by: Paul Squires on November 25, 2023, 08:07:04 AM
Yup, you're reading memory from outside the range of the array. Heaven knows what you will print.   ;D

BTW, you can catch these types of out of bounds situations by enabling the -exx compile flag (array bound sand null pointer check). You can find that flag in WinFBE's Build Configurations.
Title: Re: Testing the 'bad subscript' error - did not expect this
Post by: Bumblebee on November 25, 2023, 11:15:27 AM
Okay, I will enable it.

Do you know why multiples of 8 are causing these printouts to console?