Reading from IniFile – StringBuilder 64 byte limit

Dec 06
2012

Today I have lost nearly 4 hours because I had strange crashs in my Vulcan application.

The error returned me to the VO times with the 5333 error – the GPF.

I had this code:

method GetString( cSection as string, cEntry as string, cDefault as string ) as string
local cReturn as string
local oReturn as System.Text.StringBuilder

oReturn := System.Text.StringBuilder{}

GetPrivateProfileString( cSection, cEntry, cDefault, oReturn, INI_STRING_LEN, _cFullPath )
cReturn := oReturn:ToString()

return cReturn

and sometimes it caused very strange crashes.

I had to correct the code as follows:

method GetString( cSection as string, cEntry as string, cDefault as string ) as string
local cReturn as string
local oReturn as System.Text.StringBuilder

oReturn := System.Text.StringBuilder{ INI_STRING_LEN }

GetPrivateProfileString( cSection, cEntry, cDefault, oReturn, INI_STRING_LEN, _cFullPath )
cReturn := oReturn:ToString()

return cReturn

because otherwise the StringBuilder class was initialized only with 64 byte and the API call corrupted the runtime memory.

IMHO such an error should be detected by the stringbuilder class itself.