View previous topic :: View next topic |
Author |
Message |
mattcro
Joined: 03 Oct 2007 Posts: 327 Location: Scotland
|
Posted: Tue Jan 18, 2022 1:25 pm Post subject: Bug in instr() in Bascom-AVR 2.0.8.5 |
|
|
I've recently installed 2.0.8.5 (was using 2.0.8.3 and 2.0.8.4) and it looks like there is a bug in instr() on 2.0.8.5.003 related to the optional start position parameter. If this is non-zero, then instr() does not find a match. This works OK in previous versions as far as I can tell.
This might already be under investigation... I searched for "instr" and a recent result came up in the beta section at https://www.mcselec.com/index2.php?option=com_forum&Itemid=59&page=viewtopic&t=14891&highlight=instr (but I can't view it of course)
I wrote some sample code to test this:
Code: |
$regfile = "m1284pdef.dat" ' ATmega1284P
$hwstack = 256
$swstack = 256
$framesize = 256
$crystal = 8000000 ' External 8 MHz crystal oscillator
' Tested with and without $bigstrings - makes no difference in 2.0.8.5
'$bigstrings
Dim Source_string As String * 100
Dim Search_string As String * 100
Dim Result As Integer
Dim Start_offset As Integer
Source_string = "This is a test to check did you find me?"
Search_string = "did you find me"
' Using a start offset of zero (or not specifying the parameter) works OK in Bascom 2.0.8.5
' Using a non-zero start offset works in Bascom 2.0.8.4, but not in 2.0.8.5
Start_offset = 10
Result = Instr(start_offset , Source_string , "did you find me")
If Result > 0 Then
Print "Const substring found at " ; Result
Else
Print "Const substring not found"
End If
Result = Instr(start_offset , Source_string , Search_string)
If Result > 0 Then
Print "Variable substring found at " ; Result
Else
Print "Variable substring not found"
End If
End
|
I tried a hack in the mcs.lib _Instr code to jump over the _instr_zero return, and this does find the match but does not account for the start position (ie if source string contains the match at pos 25, but the start position was 10, then the result is 15). My assembler-fu isn't good enough to fix this, but I do see some code for this offset compensation in the 2.0.8.4 library.
(BASCOM-AVR version : 2.0.8.5 ) _________________ If all else fails, read the manual. Even better: read the manual before something fails. If you can't find it in the manual, search the forum.
BascomAVR 2.0.8.5 |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Tue Jan 18, 2022 1:57 pm Post subject: |
|
|
this is a bug.
dont know how i could miss this.
i look into it. _________________ Mark |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Tue Jan 18, 2022 2:31 pm Post subject: |
|
|
attached a fix. it is only the lbx.
this is the second upload _________________ Mark
Last edited by albertsm on Tue Jan 18, 2022 8:52 pm; edited 2 times in total |
|
Back to top |
|
|
mattcro
Joined: 03 Oct 2007 Posts: 327 Location: Scotland
|
Posted: Tue Jan 18, 2022 4:11 pm Post subject: |
|
|
Wow, quick response! Thanks Mark.
This updated mcs.lbx works better in my application.
However, I noticed that it does not find a match if the specified start position is at the position of the match (position 25 in my sample code). Maybe the search actually starts at start+1 now? I've never tried this before, but some quick tests show that it works OK in 2.0.8.4.001:
Code: |
' based on earlier test sample code
Source_string = "1234567890123456789"
Search_string = "7"
Start_offset = 7
Result = Instr(start_offset , Source_string , Search_string)
' Result is 7 in Bascom 2.0.8.4
' Result is 17 in 2.0.8.5 with mcs.lbx patched to 2.0.8.6.001
|
_________________ If all else fails, read the manual. Even better: read the manual before something fails. If you can't find it in the manual, search the forum.
BascomAVR 2.0.8.5 |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Tue Jan 18, 2022 4:23 pm Post subject: |
|
|
offset of 1 should point to the begin of the string. but so should offset 0.
i will have a look later. it should behave like 2084 but without the memory overwrite. _________________ Mark |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Tue Jan 18, 2022 8:55 pm Post subject: |
|
|
you can download the lib again. i updated it.
the problem was the offset. an offset of 0 is actual illegal since the minimum value is 1. but i changed it so that 0 is treated as 1. i tried all variations i could think of. _________________ Mark |
|
Back to top |
|
|
mattcro
Joined: 03 Oct 2007 Posts: 327 Location: Scotland
|
Posted: Wed Jan 19, 2022 1:00 pm Post subject: |
|
|
Hi Mark,
Thanks very much for the quick update! I've just tested the updated lbx from last night and it appears to be working correctly in my application code and the test code for all the variations I'm interested in. _________________ If all else fails, read the manual. Even better: read the manual before something fails. If you can't find it in the manual, search the forum.
BascomAVR 2.0.8.5 |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Wed Jan 19, 2022 1:09 pm Post subject: |
|
|
i will extend my test file. in fact i need a better way of testing. because this kind of error is not acceptable in a release version.
i got some tunnel vision. time for some changes. _________________ Mark |
|
Back to top |
|
|
|