Hi Edge Dudes
I am currently porting a Windows game to Edge (with the intent of porting to multiple platforms) and have encountered a bug with the ClassEStd::StrCpy method. Given the following test code:
The results of strncpy(dest, src, 4) is an array containing "ABCD". The results of ClassEStd::StrCpy(dest, src, 4) is an array containing "ABC\0". ClassEStd::StrCpy terminates the copied buffer at the requested length with a null character, whereas strncpy does not.
Is this by design, and should I use strncpy across all platforms?
I am currently porting a Windows game to Edge (with the intent of porting to multiple platforms) and have encountered a bug with the ClassEStd::StrCpy method. Given the following test code:
- Code:
int main(int argc, char** argv)
{
char dest[4];
const char* src = "ABCDEFGHIJKLMNOP";
strncpy(dest, src, 4);
cprintf("strncpy: Destination contains: %c%c%c%c", dest[0], dest[1], dest[2], dest[3]);
ClassEStd::StrCpy(dest, src, 4);
cprintf("\r\n\r\n");
cprintf("ClassEStd::StrCpy: Destination contains: %c%c%c%c", dest[0], dest[1], dest[2], dest[3]);
cprintf("\r\n\r\nPress any key to quit");
getch();
return 0;
}
The results of strncpy(dest, src, 4) is an array containing "ABCD". The results of ClassEStd::StrCpy(dest, src, 4) is an array containing "ABC\0". ClassEStd::StrCpy terminates the copied buffer at the requested length with a null character, whereas strncpy does not.
Is this by design, and should I use strncpy across all platforms?