At 23:18 2002-12-17 +0000, you wrote:
The code snippet below is almost text book. It works fine on Pre OS 5 versions of
PalmOS, returning the 12 character Device ROM ID.
Without adding the null terminator (line 16), the returned string has a stange character
at the end of it - so that's why it's there.
However, running it on both the Release and Debug Palm OS Simulator (utilizing PACE),
I get the string "SERIALNUMBER" returned, but when I exit the app, the simulator freezes.
It requires a soft reset.
Removing the line which adds the null terminator (line 16), re-introduces the stange charcater
at the end of the returned string, but on exiting the app, all is fine.

Can anyone shed some light on this please?

Steve

1 Char*
2 GetSysRomID()
3 {
4 Char* buffer = NULL;
5 Char* retStr = NULL;
6 UInt16 length = 0;
7 Err error = errNone;
8
9 error = SysGetROMToken(0,sysROMTokenSnum,(UInt8**)&buffer,&length);
10
11 if((!error) && (buffer) && ((UInt8)*buffer != 0xFF))
12 {
13 retStr = new Char[length];
14 CHECK_NEW_PTR(retStr); // macro to check retStr
15 StrNCopy(retStr,buffer,length);
16 retStr[length] = '\0';
17 }
18 return retStr;
19 }
You allocate a buffer of "length" characters, when you really need to allocate "length + 1" to have room for the trailing NUL terminator.

--
Ben Combee <[EMAIL PROTECTED]>
CodeWarrior for Palm OS technical lead
Palm OS programming help @ www.palmoswerks.com

--
For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/


Reply via email to