...
Noncompliant Code Example (Using strncpy() instead of wcsncpy())
This example This noncompliant code example incorrectly uses the strncpy(), which copies, at most, in an attempt to copy up to 10 wide characters but will stop copying after it encounters a null byte. Because . However, because wide characters can contain null bytes, the code can stop copying prematurely. It is important to recognize that many narrow string functions are byte functions and so can terminate prematurelycopy operation may end earlier then anticipated.
| Code Block | ||||
|---|---|---|---|---|
| ||||
#include <stddef.h>
#include <string.h>
void func(void) {
wchar_t wide_str1[] = L"0123456789";
wchar_t wide_str2[] = L"0000000000";
strncpy(wide_str2, wide_str1, 10);
} |
...