开发者

Problem with Lint warning 559

The following code generates Lint warning 559 "Size of argument no. 3 inconsistent with format" for the wsprintf call, can anyone explain why?

WCHAR szFoo[] = L"test";
WCHAR szBar[MAX_PATH];
wsprintf(szBar, L"c:\\path\\%s\\path", szFoo);

Amusingly, if I change the format type to %S the warning is no longer raised, but this of course re-interprets szFoo as LPSTR rather than LPWSTR, which is also wrong.

Of course I can just Lint-comment the warning away but I'm in开发者_开发百科terested to know why it thinks there is a problem.


Your problem is that lint doesn't know that wide strings are valid for the %s format type.

Probably the easiest fix is to add the following inline in your code, either locally with the implementation or in a header file:

//lint -printf_code("s", TCHAR*)


WCHAR* is LPWSTR, why would that be wrong?

I suggest using %lS, which interprets as LPWSTR even if Unicode is not defined

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜