Here is the code, then I will explain:
Code: Select all
; test_ascii_strings.pb
EnableExplicit
OpenConsole()
PrintN("#PB_Compiler_Version = " + #PB_Compiler_Version)
PrintN("#PB_Compiler_Unicode = " + #PB_Compiler_Unicode)
PrintN("")
Define dateStringMask.s = "yyyy-mm-dd"
Define dateStringLength.i = StringByteLength(dateStringMask, #PB_Ascii)
Define *baseWebFile
Define baseWebFile.s
Define tempIt.s = "$$$$$$$$$$$$$$ 15:26:44 GetDataFromRedis()#######> Sent 'yyyy-mm-dd' bytes for GET /ambulance/cad/active_calls.xml, yyyy-mm-dd correct $$$$$$$$$$$$$$"
Define i.i
Define j.i = 200
PrintN("Number of loops: " + Str(j))
For i=1 To j
baseWebFile + tempIt
Next
Define fileLength.i = StringByteLength(baseWebFile, #PB_Ascii)
PrintN("fileLength = " + Str(fileLength))
Define *baseWebFile = AllocateMemory(fileLength)
PokeS(*baseWebFile, baseWebFile, fileLength, #PB_Ascii)
Define *dateStringMaskAscii
PrintN("Press <enter> to continue to next step:")
Input()
*dateStringMaskAscii = AllocateMemory(dateStringLength)
PokeS(*dateStringMaskAscii, dateStringMask, dateStringLength, #PB_Ascii)
PrintN("Program complete. Press <enter> to quit")
Input()
CloseConsole()
End
When j is set to 199, the program completes successfully.
When j is set to 200, the program will die at line 33, PokeS(*dateStringMaskAscii, dateStringMask, dateStringLength, #PB_Ascii)
When j is set to 201, the program completes successfully.
If line 15, tempIt is changed, j can be set differently before the program dies.
If I remove one character from tempIt on line 15, the program dies when j is set to 202.
This happens in all versions I tested, 5.46, 5.62 and 5.70.
Here are the individual results:
Code: Select all
================================================================================================
D:\Dev\PureBasic\PureBasicTesting>test_ascii_strings
#PB_Compiler_Version = 546
#PB_Compiler_Unicode = 0
Number of loops: 199
fileLength = 29651
Press <enter> to continue to next step:
Program complete. Press <enter> to quit
================================================================================================
D:\Dev\PureBasic\PureBasicTesting>test_ascii_strings
#PB_Compiler_Version = 562
#PB_Compiler_Unicode = 1
Number of loops: 199
fileLength = 29651
Press <enter> to continue to next step:
Program complete. Press <enter> to quit
================================================================================================
D:\Dev\PureBasic\PureBasicTesting>test_ascii_strings
#PB_Compiler_Version = 570
#PB_Compiler_Unicode = 1
Number of loops: 199
fileLength = 29651
Press <enter> to continue to next step:
Program complete. Press <enter> to quit
================================================================================================
================================================================================================
D:\Dev\PureBasic\PureBasicTesting>test_ascii_strings
#PB_Compiler_Version = 546
#PB_Compiler_Unicode = 0
Number of loops: 200
fileLength = 29800
Press <enter> to continue to next step:
================================================================================================
D:\Dev\PureBasic\PureBasicTesting>test_ascii_strings
#PB_Compiler_Version = 562
#PB_Compiler_Unicode = 1
Number of loops: 200
fileLength = 29800
Press <enter> to continue to next step:
================================================================================================
D:\Dev\PureBasic\PureBasicTesting>test_ascii_strings
#PB_Compiler_Version = 570
#PB_Compiler_Unicode = 1
Number of loops: 200
fileLength = 29800
Press <enter> to continue to next step:
================================================================================================
================================================================================================
D:\Dev\PureBasic\PureBasicTesting>test_ascii_strings
#PB_Compiler_Version = 546
#PB_Compiler_Unicode = 0
Number of loops: 201
fileLength = 29949
Press <enter> to continue to next step:
Program complete. Press <enter> to quit
================================================================================================
D:\Dev\PureBasic\PureBasicTesting>test_ascii_strings
#PB_Compiler_Version = 562
#PB_Compiler_Unicode = 1
Number of loops: 201
fileLength = 29949
Press <enter> to continue to next step:
Program complete. Press <enter> to quit
================================================================================================
D:\Dev\PureBasic\PureBasicTesting>test_ascii_strings
#PB_Compiler_Version = 570
#PB_Compiler_Unicode = 1
Number of loops: 201
fileLength = 29949
Press <enter> to continue to next step:
Program complete. Press <enter> to quit
================================================================================================
Also, I don't know how I didn't hit this before, I guess the circumstances needed to be exactly right.
Luckily, this bug only took down an ambulance dispatch testing server.