Menu

#333 C++ Analysis warnings in NOTIFY_CODE_HANDLER

v1.0 (example)
closed-invalid
nobody
None
5
2026-01-15
2023-02-11
No

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)

Discussion

  • Michael Fink

    Michael Fink - 2023-02-11

    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!

     
  • Nenad Stefanovic

    • status: open --> closed-invalid
     
  • Nenad Stefanovic

    ATL issue

     

Anonymous
Anonymous

MongoDB Logo MongoDB