Hello
Following code caused me some headache and it took me a while to find the
reason. Maybe somebody will be interested, too:
UInt16 cmdLength ;
MemHandle hCmd = ClipboardGetItem( clipboardText, &cmdLength) ;
char cmd[256] ;
// Copy clipboard text into own buffer
if( hCmd != NULL )
{
const char *cmdPtr = MemHandleLock(hCmd) ;
if( cmdLength > sizeof(cmd)-1 )
cmdLength = sizeof(cmd) -1 ;
StrNCopy( cmd, cmdPtr, cmdLength ) ; // This fails on accessing low
memory address
cmd[cmdLength] = 0 ;
MemHandleUnlock( hCmd ) ;
}
The problem is that StrNCopy() accesses cmdPtr[cmdLength]. The cure to the
problem is to replace StrNCopy by MemMove.
I guess if StrNCopy was implemented differently (if the test on the string
length preceded the terminator test), there would not be any problem.
Regards
Jan Slodicka
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/support/forums/