[comp.windows.x] X Window System Bug Report

bill@MS.WASHINGTON.EDU (Bill Dunlap) (10/01/89)

			  X Window System Bug Report
			    xbugs@expo.lcs.mit.edu




VERSION:
    R3beta (as well as R2).

CLIENT MACHINE and OPERATING SYSTEM:
    IBM PC/RT running AOS 4.3 (Dec 88 release) with the hc release 2.1n
C compiler from Metaware (which comes with AOS).

DISPLAY:
    IBM APA16

WINDOW MANAGER:
    any or none.

AREA:
    server

SYNOPSIS:
    Server dies with floating point exception or goes into infinite
loop when it tries to clip a vertical dashed line.

DESCRIPTION:
    [no detailed description]

REPEAT BY:
	Compile the following program (up to END-OF-PROGRAM) with
-lX11 and run with no arguments.  If you give it one integer argument,
that will be taken as an index into dash_lists[].  The argument 0 gives
a solid line -- that gives no problems.  The problems seems to depend
on the exact placement and border width of the window.

START-OF-PROGRAM
#include <X11/Xlib.h>
#include <stdio.h>

static char *dash_lists[] = {
        "\004",                 /* solid cannot be represented with dash list */
        "\002\004",             /* dotted */
        "\004\003\002\003",     /* dash-dotted */
        "\010\003",             /* longdashed */
        "\002\002\004\002\002\002\002\002",     /* dot-dash-dot-dot */
        "\002\002\010\002",     /* dot-longdash */
        "\002\002\002\002\002\005",     /* dot-dot-dot-longspace */
        "\004\004",             /* shortdashed */
} ;
#define NLTYS (sizeof(dash_lists)/sizeof(dash_lists[0]))
int ilty ;

main(argc, argv)
int argc ;
char *argv[] ;
{
	Display *dpy ;
	Screen *scr ;
	Window plot_window ;
	Window obscuring_window ;
	XSetWindowAttributes xswa ;
	XEvent xev ;
	GC gc ;
	int i ;
	if (!(dpy= XOpenDisplay((char *)NULL))) {
		perror("Cannot open display");
		exit(-1);
	}
	(void)XSynchronize(dpy, 1) ; /* synchronize for debugging */
	scr = DefaultScreenOfDisplay(dpy) ;

	xswa.event_mask = ExposureMask ;
	xswa.background_pixel = BlackPixelOfScreen(scr);
	xswa.border_pixel = WhitePixelOfScreen(scr);
	xswa.override_redirect = True ; /* elude window manager */
	plot_window = XCreateWindow(dpy, RootWindowOfScreen(scr),
		400, 400, /* position */
		100, 128, /* size */
		2, /* border width */
		DefaultDepthOfScreen(scr), InputOutput,
		DefaultVisualOfScreen(scr),
		CWEventMask | CWBackPixel | CWBorderPixel | CWOverrideRedirect,
		&xswa) ;

	xswa.event_mask = 0L ;
	obscuring_window = XCreateWindow(dpy, RootWindowOfScreen(scr),
		375, 432, /* position */
		150, 32, /* size */
		2, /* border width */
		DefaultDepthOfScreen(scr), InputOutput,
		DefaultVisualOfScreen(scr),
		CWEventMask | CWBackPixel | CWBorderPixel | CWOverrideRedirect,
      		&xswa) ;

	gc = XCreateGC(dpy, plot_window, 0L, (XGCValues *)0) ;
	XSetForeground(dpy, gc, WhitePixelOfScreen(scr));
	ilty = argc>1 ? atoi(argv[1]) : 1 ;
	ilty = ilty % NLTYS ;
	if (ilty != 0) {
		XSetDashes(dpy, gc, 0, dash_lists[ilty], strlen(dash_lists[ilty])) ;
		XSetLineAttributes(dpy, gc,
			(unsigned int)0, /* width */
			LineOnOffDash, CapButt, JoinMiter) ;
	} else {
		XSetLineAttributes(dpy, gc,
			(unsigned int)0, /* width */
			LineSolid, CapButt, JoinMiter) ;
	}

	(void)fprintf(stderr, "ilty = %d, dash pattern is", ilty) ;
	for(i=0 ; i<strlen(dash_lists[ilty]) ; i++)
		(void)fprintf(stderr, " %d", (int)*(dash_lists[ilty]+i)) ;
	(void)fprintf(stderr, "\n") ;

	XMapWindow(dpy, plot_window) ;
	XMapWindow(dpy, obscuring_window) ;
	while (1) {
		XNextEvent(dpy, &xev) ;
		switch (xev.type) {
			case Expose :
				XDrawLine(dpy, plot_window, gc, 50, 128, 50, 0) ;
				break ;
			default :
				break ;
		}
	}
}
END-OF-PROGRAM

SAMPLE FIX:

	Here is a patch to X.V11R3/server/ddx/ibm/apa16/apa16Line.c that
fixes the problem.  This same file is called apa16line.c in 11.2.

_dome_4% diff -c apa16Line.c.orig apa16Line.c
*** apa16Line.c.orig	Tue Oct 25 03:55:52 1988
--- apa16Line.c	Fri Sep 29 15:28:53 1989
***************
*** 624,630 ****
--- 624,637 ----
      {
  	if (pdash->newLine)
  	{
+ #define BILL_FIX
+ #ifndef BILL_FIX /* hc 2.1n is confused by the next line */
  	    pt1Orig = pt1 = *pptInit++;
+ #else
+ 	    pt1 = *pptInit;
+ 	    pt1Orig = pt1 ;
+ 	    pptInit++;
+ #endif
  	    pt2 = *pptInit;
  	    adx = pt2.x - pt1.x;
  	    ady = pt2.y - pt1.y;



	Bill Dunlap
	Dept of Statistics, GN-22
	University of Washington
	Seattle, WA 98195
	bill@stat.washington.edu