[PATCH] D98798: Produce warning for performing pointer arithmetic on a null pointer.
Hans Wennborg via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu May 27 13:42:08 PDT 2021
hans added a comment.
We tried it, and the warning is still firing in a similar (but not exactly the same) way:
In file included from ../../content/browser/accessibility/browser_accessibility_manager_win.cc:19:
In file included from ../..\content/browser/renderer_host/legacy_render_widget_host_win.h:11:
../../third_party/wtl/include\atlapp.h(366,12): error: performing pointer subtraction with a null pointer may have undefined behavior [-Werror,-Wnull-pointer-subtraction]
uSize = NONCLIENTMETRICS_V1_SIZE;
^~~~~~~~~~~~~~~~~~~~~~~~
../../third_party/wtl/include\atlapp.h(248,38): note: expanded from macro 'NONCLIENTMETRICS_V1_SIZE'
#define NONCLIENTMETRICS_V1_SIZE _SIZEOF_STRUCT(NONCLIENTMETRICS, lfMessageFont)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../third_party/wtl/include\atlapp.h(228,91): note: expanded from macro '_SIZEOF_STRUCT'
#define _SIZEOF_STRUCT(structname, member) (((int)((LPBYTE)(&((structname*)0)->member) - ((LPBYTE)((structname*)0)))) + sizeof(((structname*)0)->member))
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~
Note that this time the warning is coming from a macro defined in a wtl/ header itself , which is not a system header. So I think the "don't warn in system headers" part is working correctly.
And it's good that it's got a separate flag, because for Chromium we would need to turn it off.
But as a developer I'm confused by the warning saying this _may_ have undefined behavior. Does it or doesn't it? If it does, I suppose the warning makes sense and keeping it behind a separate flag that's part of -Wextra seems reasonable.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D98798/new/
https://reviews.llvm.org/D98798
More information about the cfe-commits
mailing list