On Tue, Jan 10 2023, Christian Weisgerber <na...@mips.inka.de> wrote: > Jeremie Courreges-Anglas: > >> > https://wxcvbn.org/~jca/build-failures/amd64-clang/2023-01-03/x11/xpostit.txt >> menu.c:123:58: error: incompatible integer to pointer conversion passing >> 'int' to parameter of type 'XtPointer' (aka 'void *') [-Wint-conversion] >> XtAddCallback(entry, XtNcallback, HandleMenuSelection, i); >> ^ > > That's a pattern found in old X11 code. Callbacks take a pointer > to be able to pass arbitrary data, but instead of allocating an int > and passing a pointer to it, people just jam the int directly into > the pointer for an int -> pointer -> int conversion. > > I guess an explicit cast will fix it?
clang would compile the code, albeit with a warning: y.c:11:4: warning: cast to 'void *' from smaller integer type 'int' [-Wint-to-void-pointer-cast] I think the appropriate idiom to do this would be to include stdint.h and use a double cast, diff below tested with clang 15. But please go ahead with a shorter (void *) cast if you prefer, there's a lot of warnings in the logs anyway... Index: Makefile =================================================================== RCS file: /home/cvs/ports/x11/xpostit/Makefile,v retrieving revision 1.30 diff -u -p -r1.30 Makefile --- Makefile 11 Mar 2022 20:18:07 -0000 1.30 +++ Makefile 10 Jan 2023 15:35:30 -0000 @@ -2,7 +2,7 @@ COMMENT= PostIt (R) messages onto your X DISTNAME= xpostit3.3.1 PKGNAME= xpostit-3.3.1 -REVISION= 2 +REVISION= 3 CATEGORIES= x11 MASTER_SITES= ${MASTER_SITE_R5CONTRIB} Index: patches/patch-menu_c =================================================================== RCS file: patches/patch-menu_c diff -N patches/patch-menu_c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ patches/patch-menu_c 10 Jan 2023 15:35:05 -0000 @@ -0,0 +1,22 @@ +Use casts to appease clang 15 -Wint-conversion. + +Index: menu.c +--- menu.c.orig ++++ menu.c +@@ -49,6 +49,7 @@ static char *RCSid = "$Header: /home/harbor/davy/stuff + #include <X11/Xaw/SmeBSB.h> + #include <X11/Shell.h> + #include <stdio.h> ++#include <stdint.h> + + #include "xpostit.h" + +@@ -120,7 +121,7 @@ CreateMenuWidget() + smeBSBObjectClass, menuwidget, + NULL, 0); + +- XtAddCallback(entry, XtNcallback, HandleMenuSelection, i); ++ XtAddCallback(entry, XtNcallback, HandleMenuSelection, (void *)(uintptr_t)i); + } + + XawSimpleMenuAddGlobalActions(appcontext); -- jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF DDCC 0DFA 74AE 1524 E7EE