|
|
| Author |
Message |
cloxwerx
Joined: 01 Dec 2005
Posts: 37
Location: Tucson, Arizona
|
|
Posted: 03 December 2005, 3:48 AM Post subject: Possible Compiler Error - Function call & CStr interacti |
|
|
Here is a program that hangs. It can be made to work by either removing the RND() call or the CStr(Temp) in the next line (both statements in the Do loop).
| Code: | Option Explicit
Public Const ASCII_LF As Byte = 10
Public Const ASCII_FF As Byte = 12
Public Const ASCII_CAR As Byte = 13
'
' I/O Queue Size specifications
'
Public Const DisOutQueSize As Integer = 50
Public Const TempInPin As Byte = 13 'Pin for temperature a/d input
Public Const FreqOutPin As Byte = 15 'Pin for Tone out
Public Const DisInPin As Byte = 11 'Pin for Display serial input
Public Const DisOutPin As Byte = 10 'Pin for Display serial output
Public Const DisBaud As Long = 9600 'Display serial rate
Public Const BackLight As Byte = 20 'Backlight control code
Public Const Light80 As Byte = 204 'Backlight level=80%
Public DisOutQue (1 To DisOutQueSize) As Byte
Public TempString As String * 30 'Temperature string
Public Temp As Single 'Computed temperature
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' '
' Main Program Begins Here '
' '
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Sub Main ()
Call FreqOut(FreqOutPin,3700,3900,300) 'Send a beep to indicate power on
'
' Establish I/O queues and open serial ports
'
Call OpenQueue(DisOutQue, DisOutQueSize)
Call DefineCom3(0, DisOutPin, bx1000_1000) 'Set In/out pins and mode
Call OpenCom (3, DisBaud, DisOutQue, DisOutQue)
Call Delay (1.0) 'Let LCD power up
Call PutQueueStr(DisOutQue, Chr(ASCII_FF) & Chr(BackLight) & Chr(Light80)) 'Clear the LCD display and set backlight
Call PutQueueStr(DisOutQue, Chr(ASCII_FF) & "Test" & Chr(ASCII_CAR) & Chr(ASCII_LF))
Call Delay(1.0)
Do 'Beginning of principal processing loop
Temp=71.3 + Rnd()
TempString = "T=" & CStr(Temp) 'Convert temperature to characters
Call PutQueueStr(DisOutQue, TempString & Chr(ASCII_CAR) & Chr(ASCII_LF)) 'Display temperature
Call Delay(1.0) 'Wait a second
Loop
End Sub |
Dennis |
|
| Back to top |
|
 |
dkinzer Site Admin
Joined: 03 Sep 2005
Posts: 2499
Location: Portland, OR
|
|
Posted: 03 December 2005, 5:20 AM Post subject: |
|
|
Thanks. I've whittled it down even further:
| Code: | Dim s As String * 30
Dim f as Single
Sub Main ()
Call foo()
Do
s = CStr(f)
Debug.Print s
Loop
End Sub
Sub foo()
f = 1.0
End Sub
|
The problem appears to be related to the use of a fixed length string. |
|
| Back to top |
|
 |
dkinzer Site Admin
Joined: 03 Sep 2005
Posts: 2499
Location: Portland, OR
|
|
Posted: 03 December 2005, 7:01 AM Post subject: |
|
|
The problem has been found and fixed. When the fixed-length string is populated, the fill is being done incorrectly causing memory following the string to be overwritten.
The solution is very localized, suggesting that the probability of having introduced regression errors is low. Even so, it will take a couple of days to do a complete regression test and post a new VM version.
A temporary workaround is to either switch to a different type of string or add some buffer space following the fixed length string.
| Code: | Public TempString As String * 30 'Temperature string
Private guardBuf(1 to 30) as Byte
...
Public Sub Main()
guardBuf(1) = 0
...
|
Note that the reference to the added buffer is required if optimization is on. Otherwise, the compiler won't allocate space for it. |
|
| Back to top |
|
 |
cloxwerx
Joined: 01 Dec 2005
Posts: 37
Location: Tucson, Arizona
|
|
Posted: 03 December 2005, 15:39 PM Post subject: |
|
|
Don,
Thanks for your quick analysis. I'm sure I'll be putting the compiler through more tests with other programs soon.
Dennis |
|
| Back to top |
|
 |
|