X11: avoid null-pointer-subtraction warnings
Most recent version of XQuartz, same as before. Unfortunately, newer version of macOS => newer version of Xcode and its command line tools => newer version of clang => emulating newer version of gcc which defaults to a more recent version of StdC, I suppose, or perhaps our hints are specifying that. Whichever, it has resulted in a bunch of complaints about XtOffset() used in win/X11/winX.c: |warning: performing pointer subtraction with a null pointer has\ undefined behavior [-Wnull-pointer-subtraction] Adding -wno-null-pointer-subtraction to X11FLAGS silences them, but that would require figuring out which versions of gcc and clang added -Wnull-pointer-subtraction and its negation. Revising XtOffset() to include the ptrdiff_t casts eliminates the warnings, avoiding the need for version conditionals to deal with X11FLAGS.
This commit is contained in:
+14
-1
@@ -1,4 +1,4 @@
|
|||||||
/* NetHack 3.7 winX.h $NHDT-Date: 1643491525 2022/01/29 21:25:25 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.52 $ */
|
/* NetHack 3.7 winX.h $NHDT-Date: 1740795096 2025/02/28 18:11:36 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.65 $ */
|
||||||
/* Copyright (c) Dean Luick, 1992 */
|
/* Copyright (c) Dean Luick, 1992 */
|
||||||
/* NetHack may be freely redistributed. See license for details. */
|
/* NetHack may be freely redistributed. See license for details. */
|
||||||
|
|
||||||
@@ -26,6 +26,19 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* winX.c uses XtOffset() and the way that that macro is defined in
|
||||||
|
<X11/Intrinsic.h> triggers "performing pointer subtraction with
|
||||||
|
a null pointer has undefined behavior" warnings; this modified
|
||||||
|
edition doesn't guarantee defined behavior but does silence those
|
||||||
|
warnings without needing to know whether current compiler version
|
||||||
|
supports the '-wno-null-pointer-subtraction' option */
|
||||||
|
#ifdef XtOffset
|
||||||
|
#undef XtOffset
|
||||||
|
#define XtOffset(p_type,field) \
|
||||||
|
((Cardinal) (((ptrdiff_t) (char *) (&(((p_type) NULL)->field))) \
|
||||||
|
- ((ptrdiff_t) (char *) NULL)))
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Generic text buffer.
|
* Generic text buffer.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user