DISPLAY=:0.-1 XtScreenDatabase segfault
The following test program and any others using libXt (e.g. xterm, xfontsel) segfault when run with "DISPLAY=:0.-1" in the environment.
It seems Xt assumes DefaultScreenOfDisplay and DisplayOfScreen are inverses, when this is not the case.
Test program:
/*gcc -lX11 -lXt xt-bug.c -o xt-bug; DISPLAY=:0.-1 ./xt-bug*/
#include <X11/Intrinsic.h>
int main(int argc, char** argv) {
Display *display = XOpenDisplay (NULL);
int screen = DefaultScreen (display);
XtAppContext app_con;
(void)XtAppInitialize(&app_con, "class", NULL, 0, &argc, argv, NULL, NULL, 0);
return 0;
}
A backtrace:
Program received signal SIGSEGV, Segmentation fault.
XtScreenDatabase (screen=0x55555556c4c0) at Initialize.c:548
548 if (screen == DefaultScreenOfDisplay(dpy)) {
(gdb) bt
#0 XtScreenDatabase (screen=0x55555556c4c0) at Initialize.c:548
#1 0x00007ffff7f89fe8 in _XtDisplayInitialize (dpy=dpy@entry=0x55555556a830, pd=0x555555576f58, name=0x7fffffffe46b "a.out", urlist=urlist@entry=0x0, num_urs=num_urs@entry=0, argc=argc@entry=0x7fffffffe0dc,
argv=0x7fffffffe1e8) at Initialize.c:910
#2 0x00007ffff7f80a8a in XtOpenDisplay (app=0x555555565ca0, displayName=<optimized out>, displayName@entry=0x0, applName=<optimized out>, applName@entry=0x0, className=className@entry=0x555555556004 "class",
urlist=urlist@entry=0x0, num_urs=num_urs@entry=0, argc=0x7fffffffe0dc, argv=0x7fffffffe1e8) at Display.c:299
#3 0x00007ffff7f810b4 in _XtAppInit (app_context_return=app_context_return@entry=0x7fffffffdff8, application_class=application_class@entry=0x555555556004 "class", options=options@entry=0x0,
num_options=num_options@entry=0, argc_in_out=argc_in_out@entry=0x7fffffffe0dc, argv_in_out=argv_in_out@entry=0x7fffffffdfe8, fallback_resources=0x0) at Display.c:347
#4 0x00007ffff7f8a4bd in XtOpenApplication (app_context_return=0x7fffffffe0e8, application_class=0x555555556004 "class", options=0x0, num_options=0, argc_in_out=0x7fffffffe0dc, argv_in_out=<optimized out>,
fallback_resources=0x0, widget_class=0x7ffff7fc8440 <applicationShellClassRec>, args_in=0x0, num_args_in=0) at Initialize.c:1016
#5 0x00007ffff7f8a5ef in XtAppInitialize (app_context_return=<optimized out>, application_class=<optimized out>, options=<optimized out>, num_options=<optimized out>, argc_in_out=<optimized out>,
argv_in_out=<optimized out>, fallback_resources=0x0, args_in=0x0, num_args_in=0) at Initialize.c:1053
#6 0x00005555555551cf in main ()