Return value of function OL_0_hexToStr might be undefined

Coding and general discussion relating to the compiler

Moderators: David Barker, Jerry Messina

Post Reply
User avatar
kanderson
Posts: 17
Joined: Tue Oct 15, 2013 4:28 pm
Location: Canada
Contact:

Return value of function OL_0_hexToStr might be undefined

Post by kanderson » Thu Nov 07, 2013 10:33 pm

I recently updated to compiler version 2.2.1.8 from 2.2.1.4

It gave me a bunch of new warnings, which is great. I dealt with those problems, but one remains that I can't figure out.

[Warning] Convert.bas(580): Return value of function 'OL_0_hexToStr' might be undefined

In Convert.bas...

Code: Select all

public function hexToStr(pValue as Byte, pPad as Byte, pPadChar as Char = "0") as String(17)
   FTextAddress = @Result
   Dec08ToStrFormat(pValue, 16, pPad, pPadChar, pPadChar)
end function

...

sub dec08ToStrFormat(pValue as Byte, pBase, pPad as Byte, pPadChar, pSignChar as Char, pMax as Byte = 16)
   Dim Number as Byte
   Dim TextPtr as POSTDEC0
   Dim FirstPass as Boolean

   FirstPass = true
   if pPad > pMax then
      pPad = pMax
   endif
   inc(FTextAddress, pPad)
   TextPtr = null
   While pPad > 0
      if pValue = 0 then
         if FirstPass then
            pSignChar = "0"
         endif
         TextPtr = pSignChar
         pSignChar = pPadChar
      else
         Number = pValue Mod pBase
         if Number > 9 then
            inc(Number, 7)
         endif
         TextPtr = Number + 48
	     pValue = pValue / pBase
	  endif
	  dec(pPad)
	  FirstPass = false
   Wend
end sub
Note: FTextAddress is dim'd above ...

Code: Select all

   Dim
      ...
      FTextAddress as FSR0,   // address of result string
      ...
I'm imagining that maybe I'm passing hexToStr() an argument which has not been initialized... but not sure. Am I on the right track?

User avatar
David Barker
Swordfish Developer
Posts: 1214
Joined: Tue Oct 03, 2006 7:01 pm
Location: Saltburn by the Sea, UK
Contact:

Post by David Barker » Fri Nov 08, 2013 8:09 am

Unable to reproduce here:

Code: Select all

include "convert.bas"

dim myStr as string
myStr = hexTostr(10)
works fine - sample code?

User avatar
kanderson
Posts: 17
Joined: Tue Oct 15, 2013 4:28 pm
Location: Canada
Contact:

Figured it out

Post by kanderson » Fri Nov 08, 2013 6:52 pm

The problem was the call in one of my interrupt handlers. The culprit was if hexToStr(LChecksum,2) = LCRC then... This is in a user module I'm using (NMEA2.bas):

Code: Select all

public sub handleInterrupt(newByte as Byte)

	Save(0,Convert.hexToStr)

	...

	if hexToStr(LChecksum,2) = LCRC then					// compare extracted and calculated checksums
		NMEA.hasNewItem = True							// set the new data flag (which will hault all NMEA parsing until CLEARED)
		NMEA.readInProgress = false
		LBuffer(LIndex) = null								// tack a null on the end of the string
	EndIf
	
	...

	Restore																	// restore all system variables

end sub

So I added clear(LChecksum) to

Code: Select all

// intialize USART module
public sub initialize()

	...
	clear(LChecksum)

end sub
and that cleared up the warning. Thanks though!

Post Reply