Skip to content

Fix clang warnings about null pointer arithmetic

Alan Coopersmith requested to merge alanc/libxaw3d:clang into master
  1. List: switch from XtOffset to XtOffsetOf

Mirrors libXaw fix inherited from XFree86: 3410. Fix the last Xaw user of XtOffset (#3520, Keith Packard).

Fixes 16 -Wnull-pointer-subtraction warnings from clang 13 of the form:

List.c:81:2: warning: performing pointer subtraction with a null pointer
 has undefined behavior [-Wnull-pointer-subtraction]
        offset(list.foreground), XtRString, XtDefaultForeground},
        ^~~~~~~~~~~~~~~~~~~~~~~
List.c:77:23: note: expanded from macro 'offset'
#define offset(field) XtOffset(ListWidget, field)
                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~
  1. TextPop: do arithmetic before casting to pointer, not after

Clears warning from clang 13.0.1:

TextPop.c:646:63: warning: arithmetic on a null pointer treated as a cast
 from integer to pointer is a GNU extension [-Wnull-pointer-arithmetic]
    XtSetArg(args[num_args], XtNradioData, (XPointer) XawsdLeft + R_OFFSET);
                                         ~~~~~~~~~~~~~~~~~~~~ ^

Merge request reports

Loading