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: Select all
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17int 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;
}17 lines; 8 keywds; 12 nums; 65 ops; 5 strs; 0 coms Syntactic Coloring v0.4 - Dan East
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?
