Commit e1938c18 authored by Ulrich Sibiller's avatar Ulrich Sibiller

libNX_X11: upgrade to X.org upstream version 1.6.6

We are at X.Org libX11 upstream commit 733f64b Fixes: ArcticaProject/nx-libs #716, #719 and #720
parent 3dc45955
...@@ -63,6 +63,7 @@ from The Open Group. ...@@ -63,6 +63,7 @@ from The Open Group.
* Warning, there be dragons here.... * Warning, there be dragons here....
*/ */
#include <stdint.h>
#include <nx-X11/Xlib.h> #include <nx-X11/Xlib.h>
#include <nx-X11/Xproto.h> /* to declare xEvent */ #include <nx-X11/Xproto.h> /* to declare xEvent */
#include <nx-X11/XlibConf.h> /* for configured options like XTHREADS */ #include <nx-X11/XlibConf.h> /* for configured options like XTHREADS */
...@@ -231,10 +232,122 @@ struct _XDisplay ...@@ -231,10 +232,122 @@ struct _XDisplay
XGenericEventCookie * /* in */, XGenericEventCookie * /* in */,
XGenericEventCookie * /* out*/); XGenericEventCookie * /* out*/);
void *cookiejar; /* cookie events returned but not claimed */ void *cookiejar; /* cookie events returned but not claimed */
#ifndef LONG64
unsigned long last_request_read_upper32bit;
unsigned long request_upper32bit;
#endif
}; };
#define XAllocIDs(dpy,ids,n) (*(dpy)->idlist_alloc)(dpy,ids,n) #define XAllocIDs(dpy,ids,n) (*(dpy)->idlist_alloc)(dpy,ids,n)
/*
* access "last_request_read" and "request" with 64bit
* warning: the value argument of the SET-macros must not
* have any side-effects because it may get called twice.
*/
#ifndef LONG64
/* accessors for 32-bit unsigned long */
#define X_DPY_GET_REQUEST(dpy) \
( \
((uint64_t)(((struct _XDisplay*)dpy)->request)) \
+ (((uint64_t)(((struct _XDisplay*)dpy)->request_upper32bit)) << 32) \
)
#define X_DPY_SET_REQUEST(dpy, value) \
( \
(((struct _XDisplay*)dpy)->request = \
(value) & 0xFFFFFFFFUL), \
(((struct _XDisplay*)dpy)->request_upper32bit = \
((uint64_t)(value)) >> 32), \
(void)0 /* don't use the result */ \
)
#define X_DPY_GET_LAST_REQUEST_READ(dpy) \
( \
((uint64_t)(((struct _XDisplay*)dpy)->last_request_read)) \
+ ( \
((uint64_t)( \
((struct _XDisplay*)dpy)->last_request_read_upper32bit \
)) << 32 \
) \
)
#define X_DPY_SET_LAST_REQUEST_READ(dpy, value) \
( \
(((struct _XDisplay*)dpy)->last_request_read = \
(value) & 0xFFFFFFFFUL), \
(((struct _XDisplay*)dpy)->last_request_read_upper32bit = \
((uint64_t)(value)) >> 32), \
(void)0 /* don't use the result */ \
)
/*
* widen a 32-bit sequence number to a 64 sequence number.
* This macro makes the following assumptions:
* - ulseq refers to a sequence that has already been sent
* - ulseq means the most recent possible sequence number
* with these lower 32 bits.
*
* The following optimization is used:
* The comparison result is taken a 0 or 1 to avoid a branch.
*/
#define X_DPY_WIDEN_UNSIGNED_LONG_SEQ(dpy, ulseq) \
( \
((uint64_t)ulseq) \
+ \
(( \
((uint64_t)(((struct _XDisplay*)dpy)->request_upper32bit)) \
- (uint64_t)( \
(ulseq) > (((struct _XDisplay*)dpy)->request) \
) \
) << 32) \
)
#define X_DPY_REQUEST_INCREMENT(dpy) \
( \
((struct _XDisplay*)dpy)->request++, \
( \
(((struct _XDisplay*)dpy)->request == 0) ? ( \
((struct _XDisplay*)dpy)->request_upper32bit++ \
) : 0 \
), \
(void)0 /* don't use the result */ \
)
#define X_DPY_REQUEST_DECREMENT(dpy) \
( \
( \
(((struct _XDisplay*)dpy)->request == 0) ? (\
((struct _XDisplay*)dpy)->request--, /* wrap */ \
((struct _XDisplay*)dpy)->request_upper32bit-- \
) : ( \
((struct _XDisplay*)dpy)->request-- \
) \
), \
(void)0 /* don't use the result */ \
)
#else
/* accessors for 64-bit unsigned long */
#define X_DPY_GET_REQUEST(dpy) \
(((struct _XDisplay*)dpy)->request)
#define X_DPY_SET_REQUEST(dpy, value) \
((struct _XDisplay*)dpy)->request = (value)
#define X_DPY_GET_LAST_REQUEST_READ(dpy) \
(((struct _XDisplay*)dpy)->last_request_read)
#define X_DPY_SET_LAST_REQUEST_READ(dpy, value) \
((struct _XDisplay*)dpy)->last_request_read = (value)
#define X_DPY_WIDEN_UNSIGNED_LONG_SEQ(dpy, ulseq) ulseq
#define X_DPY_REQUEST_INCREMENT(dpy) ((struct _XDisplay*)dpy)->request++
#define X_DPY_REQUEST_DECREMENT(dpy) ((struct _XDisplay*)dpy)->request--
#endif
#ifndef _XEVENT_ #ifndef _XEVENT_
/* /*
* _QEvent datatype for use in input queueing. * _QEvent datatype for use in input queueing.
...@@ -484,6 +597,7 @@ extern void *_XGetRequest(Display *dpy, CARD8 type, size_t len); ...@@ -484,6 +597,7 @@ extern void *_XGetRequest(Display *dpy, CARD8 type, size_t len);
* GetEmptyReq is for those requests that have no arguments * GetEmptyReq is for those requests that have no arguments
* at all. * at all.
*/ */
#define GetEmptyReq(name, req) \ #define GetEmptyReq(name, req) \
req = (xReq *) _XGetRequest(dpy, X_##name, SIZEOF(xReq)) req = (xReq *) _XGetRequest(dpy, X_##name, SIZEOF(xReq))
...@@ -563,7 +677,7 @@ extern void _XFlushGCCache(Display *dpy, GC gc); ...@@ -563,7 +677,7 @@ extern void _XFlushGCCache(Display *dpy, GC gc);
dpy->bufptr += ((len) + 3) & ~3;\ dpy->bufptr += ((len) + 3) & ~3;\
} else\ } else\
_XSend(dpy, data, len);\ _XSend(dpy, data, len);\
} }
#endif /* DataRoutineIsProcedure */ #endif /* DataRoutineIsProcedure */
...@@ -701,6 +815,11 @@ typedef struct _XInternalAsync { ...@@ -701,6 +815,11 @@ typedef struct _XInternalAsync {
XPointer data; XPointer data;
} _XAsyncHandler; } _XAsyncHandler;
/*
* This struct is part of the ABI and is defined by value
* in user-code. This means that we cannot make
* the sequence-numbers 64bit.
*/
typedef struct _XAsyncEState { typedef struct _XAsyncEState {
unsigned long min_sequence_number; unsigned long min_sequence_number;
unsigned long max_sequence_number; unsigned long max_sequence_number;
......
...@@ -624,16 +624,16 @@ _XimPreeditCaretCallback(Xim im, ...@@ -624,16 +624,16 @@ _XimPreeditCaretCallback(Xim im,
*/ */
{ {
CARD8 buf[sz_ximPacketHeader + sz_ximPreeditCaretReply]; CARD8 buf[sz_ximPacketHeader + sz_ximPreeditCaretReply];
INT16 len = sz_XIMID + sz_XICID + sz_ximPreeditCaretReply; INT16 rlen = sz_XIMID + sz_XICID + sz_ximPreeditCaretReply;
int p; int p;
_XimSetHeader((XPointer)buf, XIM_PREEDIT_CARET_REPLY, 0, &len); _XimSetHeader((XPointer)buf, XIM_PREEDIT_CARET_REPLY, 0, &rlen);
p = XIM_HEADER_SIZE; p = XIM_HEADER_SIZE;
*(CARD16*)&buf[p] = (CARD16)im->private.proto.imid; p += sz_CARD16; *(CARD16*)&buf[p] = (CARD16)im->private.proto.imid; p += sz_CARD16;
*(CARD16*)&buf[p] = (CARD16)ic->private.proto.icid; p += sz_CARD16; *(CARD16*)&buf[p] = (CARD16)ic->private.proto.icid; p += sz_CARD16;
*(CARD32*)&buf[p] = (CARD32)cbs.position; *(CARD32*)&buf[p] = (CARD32)cbs.position;
if (!(_XimWriteData(im, len, buf))) { if (!(_XimWriteData(im, rlen, buf))) {
return XimCbError; return XimCbError;
} }
_XimFlushData(im); _XimFlushData(im);
......
...@@ -231,9 +231,8 @@ _XimReCreateIC(ic) ...@@ -231,9 +231,8 @@ _XimReCreateIC(ic)
_XimRegisterFilter(ic); _XimRegisterFilter(ic);
MARK_IC_CONNECTED(ic); MARK_IC_CONNECTED(ic);
if (save_ic->private.proto.ic_resources)
Xfree(save_ic->private.proto.ic_resources); Xfree(save_ic->private.proto.ic_resources);
if (save_ic->private.proto.ic_inner_resources)
Xfree(save_ic->private.proto.ic_inner_resources); Xfree(save_ic->private.proto.ic_inner_resources);
Xfree(save_ic); Xfree(save_ic);
return True; return True;
...@@ -845,22 +844,22 @@ _XimProtoICFree( ...@@ -845,22 +844,22 @@ _XimProtoICFree(
Xim im = (Xim)ic->core.im; Xim im = (Xim)ic->core.im;
#endif #endif
if (ic->private.proto.preedit_font) {
Xfree(ic->private.proto.preedit_font); Xfree(ic->private.proto.preedit_font);
ic->private.proto.preedit_font = NULL; ic->private.proto.preedit_font = NULL;
}
if (ic->private.proto.status_font) {
Xfree(ic->private.proto.status_font); Xfree(ic->private.proto.status_font);
ic->private.proto.status_font = NULL; ic->private.proto.status_font = NULL;
}
if (ic->private.proto.commit_info) { if (ic->private.proto.commit_info) {
_XimFreeCommitInfo(ic); _XimFreeCommitInfo(ic);
ic->private.proto.commit_info = NULL; ic->private.proto.commit_info = NULL;
} }
if (ic->private.proto.ic_inner_resources) {
Xfree(ic->private.proto.ic_inner_resources); Xfree(ic->private.proto.ic_inner_resources);
ic->private.proto.ic_inner_resources = NULL; ic->private.proto.ic_inner_resources = NULL;
}
#ifdef XIM_CONNECTABLE #ifdef XIM_CONNECTABLE
if (IS_SERVER_CONNECTED(im) && IS_RECONNECTABLE(im)) { if (IS_SERVER_CONNECTED(im) && IS_RECONNECTABLE(im)) {
...@@ -868,18 +867,16 @@ _XimProtoICFree( ...@@ -868,18 +867,16 @@ _XimProtoICFree(
} }
#endif /* XIM_CONNECTABLE */ #endif /* XIM_CONNECTABLE */
if (ic->private.proto.saved_icvalues) {
Xfree(ic->private.proto.saved_icvalues); Xfree(ic->private.proto.saved_icvalues);
ic->private.proto.saved_icvalues = NULL; ic->private.proto.saved_icvalues = NULL;
}
if (ic->private.proto.ic_resources) {
Xfree(ic->private.proto.ic_resources); Xfree(ic->private.proto.ic_resources);
ic->private.proto.ic_resources = NULL; ic->private.proto.ic_resources = NULL;
}
if (ic->core.hotkey) {
Xfree(ic->core.hotkey); Xfree(ic->core.hotkey);
ic->core.hotkey = NULL; ic->core.hotkey = NULL;
}
return; return;
} }
...@@ -927,6 +924,30 @@ _XimProtoDestroyIC( ...@@ -927,6 +924,30 @@ _XimProtoDestroyIC(
return; return;
} }
/*
* Some functions require the request queue from the server to be flushed
* so that the ordering of client initiated status changes and those requested
* by the server is well defined.
* _XimSync() would be the function of choice here as it should get a
* XIM_SYNC_REPLY back from the server.
* This however isn't implemented in the piece of junk that is used by most
* input servers as the server side protocol if to XIM.
* Since this code is not shipped as a library together with the client side
* XIM code but is duplicated by every input server around the world there
* is no easy fix to this but this ugly hack below.
* Obtaining an IC value from the server sends a request and empties out the
* event/server request queue until the answer to this request is found.
* Thus it is guaranteed that any pending server side request gets processed.
* This is what the hack below is doing.
*/
static void
BrokenSyncWithServer(XIC xic)
{
CARD32 dummy;
XGetICValues(xic, XNFilterEvents, &dummy, NULL);
}
static void static void
_XimProtoSetFocus( _XimProtoSetFocus(
XIC xic) XIC xic)
...@@ -957,6 +978,7 @@ _XimProtoSetFocus( ...@@ -957,6 +978,7 @@ _XimProtoSetFocus(
} }
} }
#endif /* XIM_CONNECTABLE */ #endif /* XIM_CONNECTABLE */
BrokenSyncWithServer(xic);
buf_s[0] = im->private.proto.imid; /* imid */ buf_s[0] = im->private.proto.imid; /* imid */
buf_s[1] = ic->private.proto.icid; /* icid */ buf_s[1] = ic->private.proto.icid; /* icid */
...@@ -1003,6 +1025,8 @@ _XimProtoUnsetFocus( ...@@ -1003,6 +1025,8 @@ _XimProtoUnsetFocus(
} }
#endif /* XIM_CONNECTABLE */ #endif /* XIM_CONNECTABLE */
BrokenSyncWithServer(xic);
buf_s[0] = im->private.proto.imid; /* imid */ buf_s[0] = im->private.proto.imid; /* imid */
buf_s[1] = ic->private.proto.icid; /* icid */ buf_s[1] = ic->private.proto.icid; /* icid */
......
...@@ -108,7 +108,7 @@ _XimFilterPropertyNotify( ...@@ -108,7 +108,7 @@ _XimFilterPropertyNotify(
} }
lock = True; lock = True;
for( ii = 0; ii < nitems; ii++, atoms ) { for( ii = 0; ii < nitems; ii++ ) {
if(XGetSelectionOwner (display, atoms[ii])) { if(XGetSelectionOwner (display, atoms[ii])) {
for( icb = callback_list; icb; icb = icb->next ) { for( icb = callback_list; icb; icb = icb->next ) {
if( !icb->call && !icb->destroy ) { if( !icb->call && !icb->destroy ) {
......
...@@ -82,8 +82,8 @@ struct _XimCacheStruct { ...@@ -82,8 +82,8 @@ struct _XimCacheStruct {
DTCharIndex mbused; DTCharIndex mbused;
DTCharIndex wcused; DTCharIndex wcused;
DTCharIndex utf8used; DTCharIndex utf8used;
char fname[1]; char fname[];
/* char encoding[1] */ /* char encoding[] */
}; };
static struct _XimCacheStruct* _XimCache_mmap = NULL; static struct _XimCacheStruct* _XimCache_mmap = NULL;
...@@ -281,7 +281,7 @@ _XimReadCachedDefaultTree( ...@@ -281,7 +281,7 @@ _XimReadCachedDefaultTree(
assert (m->id == XIM_CACHE_MAGIC); assert (m->id == XIM_CACHE_MAGIC);
assert (m->version == XIM_CACHE_VERSION); assert (m->version == XIM_CACHE_VERSION);
if (size != m->size || if (size != m->size ||
size < XOffsetOf (struct _XimCacheStruct, fname) + namelen + encodinglen) { size < sizeof (struct _XimCacheStruct) + namelen + encodinglen) {
fprintf (stderr, "Ignoring broken XimCache %s [%s]\n", name, encoding); fprintf (stderr, "Ignoring broken XimCache %s [%s]\n", name, encoding);
munmap (m, size); munmap (m, size);
return False; return False;
...@@ -442,7 +442,7 @@ _XimWriteCachedDefaultTree( ...@@ -442,7 +442,7 @@ _XimWriteCachedDefaultTree(
int fd; int fd;
FILE *fp; FILE *fp;
struct _XimCacheStruct *m; struct _XimCacheStruct *m;
int msize = (XOffsetOf(struct _XimCacheStruct, fname) int msize = (sizeof(struct _XimCacheStruct)
+ strlen(name) + strlen(encoding) + 2 + strlen(name) + strlen(encoding) + 2
+ XIM_CACHE_TREE_ALIGNMENT-1) & -XIM_CACHE_TREE_ALIGNMENT; + XIM_CACHE_TREE_ALIGNMENT-1) & -XIM_CACHE_TREE_ALIGNMENT;
DefTreeBase *b = &im->private.local.base; DefTreeBase *b = &im->private.local.base;
......
...@@ -61,8 +61,8 @@ _XimLocalMbLookupString(XIC xic, XKeyEvent *ev, char *buffer, int bytes, ...@@ -61,8 +61,8 @@ _XimLocalMbLookupString(XIC xic, XKeyEvent *ev, char *buffer, int bytes,
||(ic->private.local.brl_committed != 0))) { ||(ic->private.local.brl_committed != 0))) {
if (ic->private.local.brl_committed != 0) { /* Braille Event */ if (ic->private.local.brl_committed != 0) { /* Braille Event */
unsigned char pattern = ic->private.local.brl_committed; unsigned char pattern = ic->private.local.brl_committed;
char mb[XLC_PUBLIC(ic->core.im->core.lcd, mb_cur_max)]; char mb2[XLC_PUBLIC(ic->core.im->core.lcd, mb_cur_max)];
ret = _Xlcwctomb(ic->core.im->core.lcd, mb, BRL_UC_ROW | pattern); ret = _Xlcwctomb(ic->core.im->core.lcd, mb2, BRL_UC_ROW | pattern);
if(ret > bytes) { if(ret > bytes) {
if(status) *status = XBufferOverflow; if(status) *status = XBufferOverflow;
return(ret); return(ret);
...@@ -74,7 +74,7 @@ _XimLocalMbLookupString(XIC xic, XKeyEvent *ev, char *buffer, int bytes, ...@@ -74,7 +74,7 @@ _XimLocalMbLookupString(XIC xic, XKeyEvent *ev, char *buffer, int bytes,
} else { } else {
if(status) *status = XLookupChars; if(status) *status = XLookupChars;
} }
memcpy(buffer, mb, ret); memcpy(buffer, mb2, ret);
} else { } else {
if(keysym) { if(keysym) {
if(status) *status = XLookupKeySym; if(status) *status = XLookupKeySym;
......
...@@ -1617,16 +1617,15 @@ free_fontdataOM( ...@@ -1617,16 +1617,15 @@ free_fontdataOM(
FontData font_data, FontData font_data,
int font_data_count) int font_data_count)
{ {
if (!font_data)
return;
for( ; font_data_count-- ; font_data++) { for( ; font_data_count-- ; font_data++) {
if(font_data->name){
Xfree(font_data->name); Xfree(font_data->name);
font_data->name = NULL; font_data->name = NULL;
}
if(font_data->scopes){
Xfree(font_data->scopes); Xfree(font_data->scopes);
font_data->scopes = NULL; font_data->scopes = NULL;
} }
}
} }
static Status static Status
...@@ -1639,51 +1638,41 @@ close_om( ...@@ -1639,51 +1638,41 @@ close_om(
if ((data = gen->data)) { if ((data = gen->data)) {
for (count = gen->data_num; count-- > 0; data++) { for (count = gen->data_num; count-- > 0; data++) {
if (data->charset_list){
Xfree(data->charset_list); Xfree(data->charset_list);
data->charset_list = NULL; data->charset_list = NULL;
}
/* free font_data for om */ /* free font_data for om */
if (data->font_data) {
free_fontdataOM(data->font_data,data->font_data_count); free_fontdataOM(data->font_data,data->font_data_count);
Xfree(data->font_data); Xfree(data->font_data);
data->font_data = NULL; data->font_data = NULL;
}
/* free substitute for om */ /* free substitute for om */
if (data->substitute) {
free_fontdataOM(data->substitute,data->substitute_num); free_fontdataOM(data->substitute,data->substitute_num);
Xfree(data->substitute); Xfree(data->substitute);
data->substitute = NULL; data->substitute = NULL;
}
/* free vmap for om */ /* free vmap for om */
if (data->vmap) {
free_fontdataOM(data->vmap,data->vmap_num); free_fontdataOM(data->vmap,data->vmap_num);
Xfree(data->vmap); Xfree(data->vmap);
data->vmap = NULL; data->vmap = NULL;
}
/* free vrotate for om */ /* free vrotate for om */
if (data->vrotate) {
Xfree(data->vrotate); Xfree(data->vrotate);
data->vrotate = NULL; data->vrotate = NULL;
} }
}
Xfree(gen->data); Xfree(gen->data);
gen->data = NULL; gen->data = NULL;
} }
if (gen->object_name){
Xfree(gen->object_name); Xfree(gen->object_name);
gen->object_name = NULL; gen->object_name = NULL;
}
if (om->core.res_name){
Xfree(om->core.res_name); Xfree(om->core.res_name);
om->core.res_name = NULL; om->core.res_name = NULL;
}
if (om->core.res_class){
Xfree(om->core.res_class); Xfree(om->core.res_class);
om->core.res_class = NULL; om->core.res_class = NULL;
}
if (om->core.required_charset.charset_list && if (om->core.required_charset.charset_list &&
om->core.required_charset.charset_count > 0){ om->core.required_charset.charset_count > 0){
XFreeStringList(om->core.required_charset.charset_list); XFreeStringList(om->core.required_charset.charset_list);
...@@ -1692,10 +1681,9 @@ close_om( ...@@ -1692,10 +1681,9 @@ close_om(
Xfree((char*)om->core.required_charset.charset_list); Xfree((char*)om->core.required_charset.charset_list);
om->core.required_charset.charset_list = NULL; om->core.required_charset.charset_list = NULL;
} }
if (om->core.orientation_list.orientation){
Xfree(om->core.orientation_list.orientation); Xfree(om->core.orientation_list.orientation);
om->core.orientation_list.orientation = NULL; om->core.orientation_list.orientation = NULL;
}
Xfree(om); Xfree(om);
......
...@@ -60,5 +60,5 @@ XDisplayName( ...@@ -60,5 +60,5 @@ XDisplayName(
return( (char *)display ); return( (char *)display );
if ( (d = getenv( "DISPLAY" )) != (char *)NULL ) if ( (d = getenv( "DISPLAY" )) != (char *)NULL )
return( d ); return( d );
return( "" ); return( (char *) "" );
} }
...@@ -195,7 +195,7 @@ XCreateFontSet ( ...@@ -195,7 +195,7 @@ XCreateFontSet (
if (oc && def_string) { if (oc && def_string) {
*def_string = oc->core.default_string; *def_string = oc->core.default_string;
if (!*def_string) if (!*def_string)
*def_string = ""; *def_string = (char *)"";
} }
if (oc == NULL) if (oc == NULL)
......
...@@ -88,14 +88,13 @@ int *actualCount) /* RETURN */ ...@@ -88,14 +88,13 @@ int *actualCount) /* RETURN */
* unpack into null terminated strings. * unpack into null terminated strings.
*/ */
chstart = ch; chstart = ch;
chend = ch + (rlen + 1); chend = ch + rlen;
length = *(unsigned char *)ch; length = *(unsigned char *)ch;
*ch = 1; /* make sure it is non-zero for XFreeFontNames */ *ch = 1; /* make sure it is non-zero for XFreeFontNames */
for (i = 0; i < rep.nFonts; i++) { for (i = 0; i < rep.nFonts; i++) {
if (ch + length < chend) { if (ch + length < chend) {
flist[i] = ch + 1; /* skip over length */ flist[i] = ch + 1; /* skip over length */
ch += length + 1; /* find next length ... */ ch += length + 1; /* find next length ... */
if (ch <= chend) {
length = *(unsigned char *)ch; length = *(unsigned char *)ch;
*ch = '\0'; /* and replace with null-termination */ *ch = '\0'; /* and replace with null-termination */
count++; count++;
...@@ -106,13 +105,6 @@ int *actualCount) /* RETURN */ ...@@ -106,13 +105,6 @@ int *actualCount) /* RETURN */
count = 0; count = 0;
break; break;
} }
} else {
Xfree(chstart);
Xfree(flist);
flist = NULL;
count = 0;
break;
}
} }
} }
*actualCount = count; *actualCount = count;
......
...@@ -69,15 +69,20 @@ char **XGetFontPath( ...@@ -69,15 +69,20 @@ char **XGetFontPath(
/* /*
* unpack into null terminated strings. * unpack into null terminated strings.
*/ */
chend = ch + (nbytes + 1); chend = ch + nbytes;
length = *ch; length = *(unsigned char *)ch;
for (i = 0; i < rep.nPaths; i++) { for (i = 0; i < rep.nPaths; i++) {
if (ch + length < chend) { if (ch + length < chend) {
flist[i] = ch+1; /* skip over length */ flist[i] = ch+1; /* skip over length */
ch += length + 1; /* find next length ... */ ch += length + 1; /* find next length ... */
length = *ch; length = *(unsigned char *)ch;
*ch = '\0'; /* and replace with null-termination */ *ch = '\0'; /* and replace with null-termination */
count++; count++;
} else if (i == 0) {
Xfree(flist);
Xfree(ch);
flist = NULL;
break;
} else } else
flist[i] = NULL; flist[i] = NULL;
} }
......
...@@ -105,8 +105,9 @@ XImage *XGetImage ( ...@@ -105,8 +105,9 @@ XImage *XGetImage (
planes = 1; planes = 1;
} }
if (!image) if (!image) {
Xfree(data); Xfree(data);
} else {
if (planes < 1 || image->height < 1 || image->bytes_per_line < 1 || if (planes < 1 || image->height < 1 || image->bytes_per_line < 1 ||
INT_MAX / image->height <= image->bytes_per_line || INT_MAX / image->height <= image->bytes_per_line ||
INT_MAX / planes <= image->height * image->bytes_per_line || INT_MAX / planes <= image->height * image->bytes_per_line ||
...@@ -114,6 +115,7 @@ XImage *XGetImage ( ...@@ -114,6 +115,7 @@ XImage *XGetImage (
XDestroyImage(image); XDestroyImage(image);
image = NULL; image = NULL;
} }
}
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
return (image); return (image);
......
...@@ -119,11 +119,16 @@ XHostAddress *XListHosts ( ...@@ -119,11 +119,16 @@ XHostAddress *XListHosts (
_XRead (dpy, (char *) buf, nbytes); _XRead (dpy, (char *) buf, nbytes);
for (i = 0; i < reply.nHosts; i++) { for (i = 0; i < reply.nHosts; i++) {
if (bp > buf + nbytes - SIZEOF(xHostEntry))
goto fail;
op->family = ((xHostEntry *) bp)->family; op->family = ((xHostEntry *) bp)->family;
op->length =((xHostEntry *) bp)->length; op->length =((xHostEntry *) bp)->length;
if (op->family == FamilyServerInterpreted) { if (op->family == FamilyServerInterpreted) {
char *tp = (char *) (bp + SIZEOF(xHostEntry)); char *tp = (char *) (bp + SIZEOF(xHostEntry));
char *vp = memchr(tp, 0, op->length); char *vp;
if (tp > (char *) (buf + nbytes - op->length))
goto fail;
vp = memchr(tp, 0, op->length);
if (vp != NULL) { if (vp != NULL) {
sip->type = tp; sip->type = tp;
...@@ -138,6 +143,8 @@ XHostAddress *XListHosts ( ...@@ -138,6 +143,8 @@ XHostAddress *XListHosts (
sip++; sip++;
} else { } else {
op->address = (char *) (bp + SIZEOF(xHostEntry)); op->address = (char *) (bp + SIZEOF(xHostEntry));
if (op->address > (char *) (buf + nbytes - op->length))
goto fail;
} }
bp += SIZEOF(xHostEntry) + (((op->length + 3) >> 2) << 2); bp += SIZEOF(xHostEntry) + (((op->length + 3) >> 2) << 2);
op++; op++;
...@@ -149,9 +156,9 @@ XHostAddress *XListHosts ( ...@@ -149,9 +156,9 @@ XHostAddress *XListHosts (
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
return (outbuf); return (outbuf);
fail:
*enabled = reply.enabled;
*nhosts = 0;
Xfree(outbuf);
return (NULL);
} }
...@@ -74,19 +74,20 @@ char **XListExtensions( ...@@ -74,19 +74,20 @@ char **XListExtensions(
/* /*
* unpack into null terminated strings. * unpack into null terminated strings.
*/ */
chend = ch + (rlen + 1); chend = ch + rlen;
length = *ch; length = *(unsigned char *)ch;
for (i = 0; i < rep.nExtensions; i++) { for (i = 0; i < rep.nExtensions; i++) {
if (ch + length < chend) { if (ch + length < chend) {
list[i] = ch+1; /* skip over length */ list[i] = ch+1; /* skip over length */
ch += length + 1; /* find next length ... */ ch += length + 1; /* find next length ... */
if (ch <= chend) { length = *(unsigned char *)ch;
length = *ch;
*ch = '\0'; /* and replace with null-termination */ *ch = '\0'; /* and replace with null-termination */
count++; count++;
} else { } else if (i == 0) {
list[i] = NULL; Xfree(list);
} Xfree(ch);
list = NULL;
break;
} else } else
list[i] = NULL; list[i] = NULL;
} }
......
...@@ -211,7 +211,7 @@ XSetCommand ( ...@@ -211,7 +211,7 @@ XSetCommand (
int argc) int argc)
{ {
register int i; register int i;
register int nbytes; size_t nbytes;
register char *buf, *bp; register char *buf, *bp;
for (i = 0, nbytes = 0; i < argc; i++) { for (i = 0, nbytes = 0; i < argc; i++) {
nbytes += safestrlen(argv[i]) + 1; nbytes += safestrlen(argv[i]) + 1;
...@@ -295,7 +295,7 @@ XSetClassHint( ...@@ -295,7 +295,7 @@ XSetClassHint(
{ {
char *class_string; char *class_string;
char *s; char *s;
int len_nm, len_cl; size_t len_nm, len_cl;
len_nm = safestrlen(classhint->res_name); len_nm = safestrlen(classhint->res_name);
len_cl = safestrlen(classhint->res_class); len_cl = safestrlen(classhint->res_class);
......
...@@ -50,6 +50,7 @@ XStoreColor( ...@@ -50,6 +50,7 @@ XStoreColor(
citem->green = def->green; citem->green = def->green;
citem->blue = def->blue; citem->blue = def->blue;
citem->flags = def->flags; /* do_red, do_green, do_blue */ citem->flags = def->flags; /* do_red, do_green, do_blue */
citem->pad = 0;
UnlockDisplay(dpy); UnlockDisplay(dpy);
......
...@@ -53,6 +53,7 @@ XStoreColors( ...@@ -53,6 +53,7 @@ XStoreColors(
citem.green = defs[i].green; citem.green = defs[i].green;
citem.blue = defs[i].blue; citem.blue = defs[i].blue;
citem.flags = defs[i].flags; citem.flags = defs[i].flags;
citem.pad = 0;
/* note that xColorItem doesn't contain all 16-bit quantities, so /* note that xColorItem doesn't contain all 16-bit quantities, so
we can't use Data16 */ we can't use Data16 */
......
...@@ -115,7 +115,7 @@ XStringToKeysym(_Xconst char *s) ...@@ -115,7 +115,7 @@ XStringToKeysym(_Xconst char *s)
{ {
XrmValue result; XrmValue result;
XrmRepresentation from_type; XrmRepresentation from_type;
char c; char d;
XrmQuark names[2]; XrmQuark names[2];
names[0] = _XrmInternalStringToQuark(s, p - s - 1, sig, False); names[0] = _XrmInternalStringToQuark(s, p - s - 1, sig, False);
...@@ -126,10 +126,10 @@ XStringToKeysym(_Xconst char *s) ...@@ -126,10 +126,10 @@ XStringToKeysym(_Xconst char *s)
val = 0; val = 0;
for (i = 0; i < result.size - 1; i++) for (i = 0; i < result.size - 1; i++)
{ {
c = ((char *)result.addr)[i]; d = ((char *)result.addr)[i];
if ('0' <= c && c <= '9') val = (val<<4)+c-'0'; if ('0' <= d && d <= '9') val = (val<<4)+d-'0';
else if ('a' <= c && c <= 'f') val = (val<<4)+c-'a'+10; else if ('a' <= d && d <= 'f') val = (val<<4)+d-'a'+10;
else if ('A' <= c && c <= 'F') val = (val<<4)+c-'A'+10; else if ('A' <= d && d <= 'F') val = (val<<4)+d-'A'+10;
else return NoSymbol; else return NoSymbol;
} }
return val; return val;
......
...@@ -836,8 +836,12 @@ _XWaitForReadable( ...@@ -836,8 +836,12 @@ _XWaitForReadable(
static int sync_hazard(Display *dpy) static int sync_hazard(Display *dpy)
{ {
unsigned long span = dpy->request - dpy->last_request_read; /*
unsigned long hazard = min((dpy->bufmax - dpy->buffer) / SIZEOF(xReq), 65535 - 10); * "span" and "hazard" need to be signed such that the ">=" comparision
* works correctly in the case that hazard is greater than 65525
*/
int64_t span = X_DPY_GET_REQUEST(dpy) - X_DPY_GET_LAST_REQUEST_READ(dpy);
int64_t hazard = min((dpy->bufmax - dpy->buffer) / SIZEOF(xReq), 65535 - 10);
return span >= 65535 - hazard - 10; return span >= 65535 - hazard - 10;
} }
...@@ -876,7 +880,7 @@ void _XSeqSyncFunction( ...@@ -876,7 +880,7 @@ void _XSeqSyncFunction(
return; return;
} }
#endif /* NX_TRANS_SOCKET */ #endif /* NX_TRANS_SOCKET */
if ((dpy->request - dpy->last_request_read) >= (65535 - BUFSIZE/SIZEOF(xReq))) { if ((X_DPY_GET_REQUEST(dpy) - X_DPY_GET_LAST_REQUEST_READ(dpy)) >= (65535 - BUFSIZE/SIZEOF(xReq))) {
GetEmptyReq(GetInputFocus, req); GetEmptyReq(GetInputFocus, req);
(void) _XReply (dpy, (xReply *)&rep, 0, xTrue); (void) _XReply (dpy, (xReply *)&rep, 0, xTrue);
sync_while_locked(dpy); sync_while_locked(dpy);
...@@ -2072,9 +2076,9 @@ _XSetLastRequestRead( ...@@ -2072,9 +2076,9 @@ _XSetLastRequestRead(
register Display *dpy, register Display *dpy,
register xGenericReply *rep) register xGenericReply *rep)
{ {
register unsigned long newseq, lastseq; register uint64_t newseq, lastseq;
lastseq = dpy->last_request_read; lastseq = X_DPY_GET_LAST_REQUEST_READ(dpy);
/* /*
* KeymapNotify has no sequence number, but is always guaranteed * KeymapNotify has no sequence number, but is always guaranteed
* to immediately follow another event, except when generated via * to immediately follow another event, except when generated via
...@@ -2083,30 +2087,31 @@ _XSetLastRequestRead( ...@@ -2083,30 +2087,31 @@ _XSetLastRequestRead(
if ((rep->type & 0x7f) == KeymapNotify) if ((rep->type & 0x7f) == KeymapNotify)
return(lastseq); return(lastseq);
newseq = (lastseq & ~((unsigned long)0xffff)) | rep->sequenceNumber; newseq = (lastseq & ~((uint64_t)0xffff)) | rep->sequenceNumber;
if (newseq < lastseq) { if (newseq < lastseq) {
newseq += 0x10000; newseq += 0x10000;
if (newseq > dpy->request) { if (newseq > X_DPY_GET_REQUEST(dpy)) {
#ifdef NX_TRANS_SOCKET #ifdef NX_TRANS_SOCKET
if (_NXLostSequenceFunction != NULL) if (_NXLostSequenceFunction != NULL)
{ {
(*_NXLostSequenceFunction)(dpy, newseq, dpy->request, (*_NXLostSequenceFunction)(dpy, newseq, X_DPY_GET_REQUEST(dpy),
(unsigned int) rep->type); (unsigned int) rep->type);
} }
else else
#endif /* #ifdef NX_TRANS_SOCKET */ #endif /* #ifdef NX_TRANS_SOCKET */
{ {
(void) fprintf (stderr, (void) fprintf (stderr,
"Xlib: sequence lost (0x%lx > 0x%lx) in reply type 0x%x!\n", "Xlib: sequence lost (0x%llx > 0x%llx) in reply type 0x%x!\n",
newseq, dpy->request, (unsigned long long)newseq,
(unsigned long long)(X_DPY_GET_REQUEST(dpy)),
(unsigned int) rep->type); (unsigned int) rep->type);
} }
newseq -= 0x10000; newseq -= 0x10000;
} }
} }
dpy->last_request_read = newseq; X_DPY_SET_LAST_REQUEST_READ(dpy, newseq);
return(newseq); return(newseq);
} }
...@@ -2924,12 +2929,9 @@ void _XEnq( ...@@ -2924,12 +2929,9 @@ void _XEnq(
else if ((qelt = Xmalloc(sizeof(_XQEvent))) == NULL) { else if ((qelt = Xmalloc(sizeof(_XQEvent))) == NULL) {
/* Malloc call failed! */ /* Malloc call failed! */
ESET(ENOMEM); ESET(ENOMEM);
#ifdef NX_TRANS_SOCKET
_XIOError(dpy); _XIOError(dpy);
#ifdef NX_TRANS_SOCKET
return; return;
#else
_XIOError(dpy);
#endif #endif
} }
qelt->next = NULL; qelt->next = NULL;
...@@ -3590,10 +3592,10 @@ static int _XPrintDefaultError( ...@@ -3590,10 +3592,10 @@ static int _XPrintDefaultError(
mesg, BUFSIZ); mesg, BUFSIZ);
fputs(" ", fp); fputs(" ", fp);
(void) fprintf(fp, mesg, event->serial); (void) fprintf(fp, mesg, event->serial);
XGetErrorDatabaseText(dpy, mtype, "CurrentSerial", "Current Serial #%d", XGetErrorDatabaseText(dpy, mtype, "CurrentSerial", "Current Serial #%lld",
mesg, BUFSIZ); mesg, BUFSIZ);
fputs("\n ", fp); fputs("\n ", fp);
(void) fprintf(fp, mesg, dpy->request); (void) fprintf(fp, mesg, (unsigned long long)(X_DPY_GET_REQUEST(dpy)));
fputs("\n", fp); fputs("\n", fp);
if (event->error_code == BadImplementation) return 0; if (event->error_code == BadImplementation) return 0;
return 1; return 1;
...@@ -3658,17 +3660,17 @@ int _XError ( ...@@ -3658,17 +3660,17 @@ int _XError (
return 0; return 0;
if (_XErrorFunction != NULL) { if (_XErrorFunction != NULL) {
int rtn_val; int rtn_val;
#if defined(XTHREADS) && !USE_XCB #ifdef XTHREADS
if (dpy->lock) if (dpy->lock)
(*dpy->lock->user_lock_display)(dpy); (*dpy->lock->user_lock_display)(dpy);
UnlockDisplay(dpy); UnlockDisplay(dpy);
#endif /* XTHREADS && !USE_XCB */ #endif
rtn_val = (*_XErrorFunction)(dpy, (XErrorEvent *)&event); /* upcall */ rtn_val = (*_XErrorFunction)(dpy, (XErrorEvent *)&event); /* upcall */
#if defined(XTHREADS) && !USE_XCB #ifdef XTHREADS
LockDisplay(dpy); LockDisplay(dpy);
if (dpy->lock) if (dpy->lock)
(*dpy->lock->user_unlock_display)(dpy); (*dpy->lock->user_unlock_display)(dpy);
#endif /* XTHREADS && !USE_XCB */ #endif
return rtn_val; return rtn_val;
} else { } else {
return _XDefaultError(dpy, (XErrorEvent *)&event); return _XDefaultError(dpy, (XErrorEvent *)&event);
...@@ -3999,7 +4001,7 @@ void *_XGetRequest(Display *dpy, CARD8 type, size_t len) ...@@ -3999,7 +4001,7 @@ void *_XGetRequest(Display *dpy, CARD8 type, size_t len)
req->reqType = type; req->reqType = type;
req->length = len / 4; req->length = len / 4;
dpy->bufptr += len; dpy->bufptr += len;
dpy->request++; X_DPY_REQUEST_INCREMENT(dpy);
return req; return req;
} }
......
...@@ -795,6 +795,9 @@ LINEAR_RGB_InitSCCData( ...@@ -795,6 +795,9 @@ LINEAR_RGB_InitSCCData(
return(XcmsSuccess); return(XcmsSuccess);
FreeBlueTblElements:
Xfree(pScreenData->pBlueTbl->pBase);
FreeBlueTbl: FreeBlueTbl:
Xfree(pScreenData->pBlueTbl); Xfree(pScreenData->pBlueTbl);
......
...@@ -314,7 +314,7 @@ field2( ...@@ -314,7 +314,7 @@ field2(
/* Find Field 1 */ /* Find Field 1 */
while (!isgraph(*pBuf)) { while (!isgraph(*pBuf)) {
if ((*pBuf != '\n') || (*pBuf != '\0')) { if ((*pBuf == '\n') || (*pBuf == '\0')) {
return(XcmsFailure); return(XcmsFailure);
} }
if (isspace(*pBuf) || (*pBuf == delim)) { if (isspace(*pBuf) || (*pBuf == delim)) {
......
...@@ -142,6 +142,7 @@ _XcmsGetProperty( ...@@ -142,6 +142,7 @@ _XcmsGetProperty(
if (xgwp_ret != Success || format_ret == 0 || nitems_ret == 0) { if (xgwp_ret != Success || format_ret == 0 || nitems_ret == 0) {
/* the property does not exist or is of an unexpected type or /* the property does not exist or is of an unexpected type or
getting window property failed */ getting window property failed */
XFree (prop_ret);
return(XcmsFailure); return(XcmsFailure);
} }
......
...@@ -216,24 +216,22 @@ XkbFreeNames(XkbDescPtr xkb, unsigned which, Bool freeMap) ...@@ -216,24 +216,22 @@ XkbFreeNames(XkbDescPtr xkb, unsigned which, Bool freeMap)
type = map->types; type = map->types;
for (i = 0; i < map->num_types; i++, type++) { for (i = 0; i < map->num_types; i++, type++) {
if (type->level_names != NULL) {
_XkbFree(type->level_names); _XkbFree(type->level_names);
type->level_names = NULL; type->level_names = NULL;
} }
} }
} }
} if (which & XkbKeyNamesMask) {
if ((which & XkbKeyNamesMask) && (names->keys != NULL)) {
_XkbFree(names->keys); _XkbFree(names->keys);
names->keys = NULL; names->keys = NULL;
names->num_keys = 0; names->num_keys = 0;
} }
if ((which & XkbKeyAliasesMask) && (names->key_aliases)) { if (which & XkbKeyAliasesMask) {
_XkbFree(names->key_aliases); _XkbFree(names->key_aliases);
names->key_aliases = NULL; names->key_aliases = NULL;
names->num_key_aliases = 0; names->num_key_aliases = 0;
} }
if ((which & XkbRGNamesMask) && (names->radio_groups)) { if (which & XkbRGNamesMask) {
_XkbFree(names->radio_groups); _XkbFree(names->radio_groups);
names->radio_groups = NULL; names->radio_groups = NULL;
names->num_rg = 0; names->num_rg = 0;
......
...@@ -1021,19 +1021,19 @@ cstoct( ...@@ -1021,19 +1021,19 @@ cstoct(
) { ) {
while (csstr_len > 0 && ct_len > 0) { while (csstr_len > 0 && ct_len > 0) {
unsigned char ch = * (const unsigned char *) csptr; unsigned char ch = * (const unsigned char *) csptr;
int char_size = (ch < 0xc0 ? 1 : int ch_size = (ch < 0xc0 ? 1 :
ch < 0xe0 ? 2 : ch < 0xe0 ? 2 :
ch < 0xf0 ? 3 : ch < 0xf0 ? 3 :
ch < 0xf8 ? 4 : ch < 0xf8 ? 4 :
ch < 0xfc ? 5 : ch < 0xfc ? 5 :
6); 6);
int i; int i;
if (!(csstr_len >= char_size && ct_len >= char_size)) if (!(csstr_len >= ch_size && ct_len >= ch_size))
break; break;
for (i = char_size; i > 0; i--) for (i = ch_size; i > 0; i--)
*ctptr++ = *csptr++; *ctptr++ = *csptr++;
csstr_len -= char_size; csstr_len -= ch_size;
ct_len -= char_size; ct_len -= ch_size;
} }
} else { } else {
while (csstr_len > 0 && ct_len > 0) { while (csstr_len > 0 && ct_len > 0) {
......
...@@ -781,7 +781,7 @@ f_right_brace( ...@@ -781,7 +781,7 @@ f_right_brace(
case S_VALUE: case S_VALUE:
if (! store_to_database(db)) if (! store_to_database(db))
return 0; return 0;
/* fall into next case */ /* fall through - to next case */
case S_CATEGORY: case S_CATEGORY:
if (parse_info.name[parse_info.nest_depth] != NULL) { if (parse_info.name[parse_info.nest_depth] != NULL) {
Xfree(parse_info.name[parse_info.nest_depth]); Xfree(parse_info.name[parse_info.nest_depth]);
......
...@@ -77,6 +77,7 @@ create( ...@@ -77,6 +77,7 @@ create(
return lcd; return lcd;
err: err:
Xfree(lcd->core);
Xfree(lcd); Xfree(lcd);
return (XLCd) NULL; return (XLCd) NULL;
} }
......
...@@ -97,6 +97,7 @@ create( ...@@ -97,6 +97,7 @@ create(
return lcd; return lcd;
err: err:
Xfree(lcd->core);
Xfree(lcd); Xfree(lcd);
return (XLCd) NULL; return (XLCd) NULL;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment