It is currently Sat Aug 24, 2019 11:41 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: String manipulation bug
PostPosted: Tue May 07, 2019 10:01 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Sep 22, 2010 1:50 am
Posts: 796
Location: Bradenton, FL
Found this bug while migrating to Unicode, the premise of which is an error Poking a string, after creating a large string.

Here is the code, then I will explain:
Code:
; 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

Modify line 19, 'j'.
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:
================================================================================================

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

================================================================================================


Where you see 'Program complete. Press <enter> to quit', the program worked correctly. Not sure why, I can't an OnErrorCall to give me any information. Purifier is enabled. I wanted to include just the barebones program, to see if people can recreate the issue.

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.


Top
 Profile  
Reply with quote  
 Post subject: Re: String manipulation bug
PostPosted: Tue May 07, 2019 11:04 pm 
Offline
Addict
Addict
User avatar

Joined: Mon Sep 15, 2003 5:55 am
Posts: 1340
Code:
AllocateMemory(n + SizeOf(Ascii))
or
Code:
PokeS(*ptr, str$, n, #PB_Ascii | #PB_String_NoZero)

c ya,
nco2k

_________________
If OSVersion() = #PB_OS_Windows_ME : End : EndIf


Last edited by nco2k on Tue May 07, 2019 11:34 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: String manipulation bug
PostPosted: Tue May 07, 2019 11:25 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Sep 22, 2010 1:50 am
Posts: 796
Location: Bradenton, FL
nco2k wrote:
Code:
AllocateMemory(n + SizeOf(Character))
or
Code:
PokeS(*ptr, str$, n, #PB_Ascii | #PB_String_NoZero)

c ya,
nco2k


No.


Top
 Profile  
Reply with quote  
 Post subject: Re: String manipulation bug
PostPosted: Tue May 07, 2019 11:28 pm 
Offline
Addict
Addict
User avatar

Joined: Mon Sep 15, 2003 5:55 am
Posts: 1340
yes.

Code:
; 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 + SizeOf(Ascii))
PokeS(*baseWebFile, baseWebFile, fileLength, #PB_Ascii)
Define *dateStringMaskAscii
PrintN("Press <enter> to continue to next step:")
Input()

*dateStringMaskAscii = AllocateMemory(dateStringLength + SizeOf(Ascii))
PokeS(*dateStringMaskAscii, dateStringMask, dateStringLength, #PB_Ascii)
PrintN("Program complete. Press <enter> to quit")
Input()

CloseConsole()
End

edit: oops i meant n + SizeOf(Ascii). either way, both works with your code.

c ya,
nco2k

_________________
If OSVersion() = #PB_OS_Windows_ME : End : EndIf


Last edited by nco2k on Tue May 07, 2019 11:35 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: String manipulation bug
PostPosted: Tue May 07, 2019 11:35 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Sep 22, 2010 1:50 am
Posts: 796
Location: Bradenton, FL
I understand what you did, it works, and I appreciate your input.

But why does my version work with 199 or 201 loops, and not 200?

Should it be consistent???


Top
 Profile  
Reply with quote  
 Post subject: Re: String manipulation bug
PostPosted: Wed May 08, 2019 12:07 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Sep 22, 2010 1:50 am
Posts: 796
Location: Bradenton, FL
Fred, Freak and the powers that be can mark this as 'not a bug' if needed.

Thanks to 'nco2k' for pointing out the issue with not including '#PB_String_NoZero'.

I just have to question the inconsistency. And that it might throw others a curve as well.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye