다음을 통해 공유


PREfast Warning 276 (Windows CE 5.0)

Send Feedback

276 - Cast between semantically different string types.
Additional Information: char* to wchar_t*.
Consequence: This will result in garbled strings and possible crashes on 64-bit builds.

This warning indicates a potentially incorrect cast from an ANSI string (char_t*) to a Unicode string (wchar_t *).

Because Unicode strings have a character size of 2 bytes, this cast can yield strings that are not correctly terminated. Using such strings with the wcs* library of functions can cause buffer overruns and access violations.

Example

Defective Source

LPWSTR pSrc = (LPWSTR)"a";

WCHAR szBuffer[2];

wcscpy(szBuffer,
       pSrc);

Corrected Source

LPWSTR pSrc = L"a";

WCHAR szBuffer[100];

wcscpy(szBuffer,
       pSrc);

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.