C++ Analysis warnings in NOTIFY_CODE_HANDLER
Brought to you by: nenadstefanovic
When running Code Analysis over my WTL project, I get some warnings in the usage of the NOTIFY_CODE_HANDLER and REFLECT_NOTIFY_CODE_HANDLER methods:
warning C26454: Arithmetic overflow: '-' operation produces a negative unsigned result at compile time (io.5).
The code looks like this:
NOTIFY_CODE_HANDLER(LVN_GETDISPINFO, OnGetDispInfo)
LVN_GETDISPINFO expands to (LVN_FIRST-77), which finally expands to ((0U-100U)-77), and in the macros, it is compared against NMHDR's code, which is a UINT:
#define NOTIFY_CODE_HANDLER(cd, func) \ if(uMsg == WM_NOTIFY && cd == ((LPNMHDR)lParam)->code) \ When searching for the comparison, it seems also NOTIFY_HANDLER and REFLECTED_NOTIFY_HANDLER may trigger the analysis warning.
The fix for the analysis warning would problably be something like
((UINT)(cd)) == ((LPNMHDR)lParam)->code)
Anonymous
I'm sorry for the noise, but this actually is no WTL bug, but it's in ATL's atlwin.h. Do you maybe know where to report this for ATL? Thanks!
ATL issue