From a765857aaa450862f6a3dc5de811671fbc82ca61 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Sat, 1 Jun 2019 00:52:06 +0200 Subject: Remove the Must_have_memory hack. We are not using any alloc function that respects that variable, so lets drop it. Backport of this commit: commit 0ce61e21d6d7dcca0090e319bbcdb678570f2c3f Author: Adam Jackson Date: Fri Oct 3 16:05:19 2008 -0400 Remove the Must_have_memory hack. Also remove an astonishing amount of misunderstanding of how casts work. --- nx-X11/programs/Xserver/hw/nxagent/NXevents.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'nx-X11/programs/Xserver/hw') diff --git a/nx-X11/programs/Xserver/hw/nxagent/NXevents.c b/nx-X11/programs/Xserver/hw/nxagent/NXevents.c index 43dfe8613..78d74a0d5 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/NXevents.c +++ b/nx-X11/programs/Xserver/hw/nxagent/NXevents.c @@ -367,10 +367,8 @@ XYToWindow(int x, int y) if (spriteTraceGood >= spriteTraceSize) { spriteTraceSize += 10; - Must_have_memory = TRUE; /* XXX */ - spriteTrace = (WindowPtr *)realloc( + spriteTrace = realloc( spriteTrace, spriteTraceSize*sizeof(WindowPtr)); - Must_have_memory = FALSE; /* XXX */ } spriteTrace[spriteTraceGood++] = pWin; pWin = pWin->firstChild; -- cgit v1.2.3 From d8f5e647c92b73835665c555d06c8814c7d0dbb5 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Thu, 30 May 2019 23:50:53 +0200 Subject: NXwindow.c: fix compiler warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit NXwindow.c:265:27: warning: ‘%d’ directive writing between 1 and 11 bytes into a region of size 10 [-Wformat-overflow=] sprintf(artsd_port,"%d", nPort); ^~ NXwindow.c:265:26: note: directive argument in the range [-2147476648, 2147483647] sprintf(artsd_port,"%d", nPort); ^~~~ NXwindow.c:265:7: note: ‘sprintf’ output between 2 and 12 bytes into a destination of size 10 sprintf(artsd_port,"%d", nPort); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --- nx-X11/programs/Xserver/hw/nxagent/NXwindow.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nx-X11/programs/Xserver/hw') diff --git a/nx-X11/programs/Xserver/hw/nxagent/NXwindow.c b/nx-X11/programs/Xserver/hw/nxagent/NXwindow.c index 2fe37f79c..0851daf97 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/NXwindow.c +++ b/nx-X11/programs/Xserver/hw/nxagent/NXwindow.c @@ -296,7 +296,7 @@ InitRootWindow(WindowPtr pWin) #ifdef NXAGENT_ARTSD { char artsd_port[10]; - int nPort; + short int nPort; extern void nxagentPropagateArtsdProperties(ScreenPtr pScreen, char *port); nPort = atoi(display) + 7000; sprintf(artsd_port,"%d", nPort); -- cgit v1.2.3 From a3e0376f95cb57aeda12438313cba67b1690d685 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Wed, 29 May 2019 23:52:44 +0200 Subject: Window.c: remove leftover (commented) code This was eventually replaced by nxagentAddConfiguredWindow(pWin, CW_Map) some lines below which is just leading to the same code being executed some time later. (nxagentAddConfiguredWindow() will add a window to a list. nxagentFlushConfiguredWindow() is called at certain points to update all windows in that list in one go. "update" here means calling XConfigureWindow() or XMapWindow() on the real display.) --- nx-X11/programs/Xserver/hw/nxagent/Window.c | 14 -------------- 1 file changed, 14 deletions(-) (limited to 'nx-X11/programs/Xserver/hw') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Window.c b/nx-X11/programs/Xserver/hw/nxagent/Window.c index 8307c3de4..7d98d25fe 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Window.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Window.c @@ -1942,20 +1942,6 @@ Bool nxagentRealizeWindow(WindowPtr pWin) #endif */ - /* - * Mapping of the root window is called by - * InitRootWindow in DIX. Skip the operation - * if we are in rootless mode. - */ - - /* - * if (!nxagentOption(Rootless) || - * nxagentRootlessWindow != pWin) - * { - * XMapWindow(nxagentDisplay, nxagentWindow(pWin)); - * } - */ - #ifdef TEST if (nxagentOption(Rootless) && nxagentLastWindowDestroyed) { -- cgit v1.2.3 From 9f5ddede95086c6f31efe89ed228ac035a89a8e5 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Thu, 30 May 2019 00:10:43 +0200 Subject: Window.c: Drop defines CWParent and CWStackingOrder They were just aliases to already existing defines and were not used stringently. So we had mix of aliased and non-aliased uses which is confusing when trying to understand the code... --- nx-X11/programs/Xserver/hw/nxagent/Window.c | 28 ++++++++++++++-------------- nx-X11/programs/Xserver/hw/nxagent/Windows.h | 3 --- 2 files changed, 14 insertions(+), 17 deletions(-) (limited to 'nx-X11/programs/Xserver/hw') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Window.c b/nx-X11/programs/Xserver/hw/nxagent/Window.c index 7d98d25fe..f602d0ed3 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Window.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Window.c @@ -727,7 +727,7 @@ Bool nxagentPositionWindow(WindowPtr pWin, int x, int y) (void *) pWin, nxagentWindow(pWin), x, y); #endif - nxagentAddConfiguredWindow(pWin, CWParent | CWX | CWY | CWWidth | + nxagentAddConfiguredWindow(pWin, CWSibling | CWX | CWY | CWWidth | CWHeight | CWBorderWidth); return True; @@ -1284,7 +1284,7 @@ void nxagentConfigureWindow(WindowPtr pWin, unsigned int mask) { if (mask & CW_RootlessRestack) { - mask = CWStackingOrder; + mask = CWStackMode; } } @@ -1299,7 +1299,7 @@ void nxagentConfigureWindow(WindowPtr pWin, unsigned int mask) if (mask & CW_Update) { - mask |= CWX | CWY | CWWidth | CWHeight | CWBorderWidth | CWStackingOrder; + mask |= CWX | CWY | CWWidth | CWHeight | CWBorderWidth | CWStackMode; } if (mask & CWX) @@ -1378,7 +1378,7 @@ void nxagentConfigureWindow(WindowPtr pWin, unsigned int mask) MAKE_SYNC_CONFIGURE_WINDOW; } - if (mask & CWStackingOrder && + if (mask & CWStackMode && nxagentWindowPriv(pWin)->siblingAbove != nxagentWindowSiblingAbove(pWin)) { WindowPtr pSib; @@ -1478,7 +1478,7 @@ void nxagentConfigureWindow(WindowPtr pWin, unsigned int mask) * really needed? * * - * else if (mask & CWStackingOrder) + * else if (mask & CWStackMode) * { * if (nxagentSplashWindow) * { @@ -1920,12 +1920,12 @@ Bool nxagentRealizeWindow(WindowPtr pWin) /* * Not needed. * - * nxagentConfigureWindow(pWin, CWStackingOrder); + * nxagentConfigureWindow(pWin, CWStackMode); * * nxagentFlushConfigureWindow(); */ - nxagentAddConfiguredWindow(pWin, CWStackingOrder); + nxagentAddConfiguredWindow(pWin, CWStackMode); nxagentAddConfiguredWindow(pWin, CW_Shape); /* add by dimbor */ @@ -2116,10 +2116,10 @@ void nxagentCopyWindow(WindowPtr pWin, xPoint oldOrigin, RegionPtr oldRegion) void nxagentClipNotify(WindowPtr pWin, int dx, int dy) { /* - * nxagentConfigureWindow(pWin, CWStackingOrder); + * nxagentConfigureWindow(pWin, CWStackMode); */ - nxagentAddConfiguredWindow(pWin, CWStackingOrder); + nxagentAddConfiguredWindow(pWin, CWStackMode); nxagentAddConfiguredWindow(pWin, CW_Shape); #ifndef NXAGENT_SHAPE @@ -3572,10 +3572,10 @@ void nxagentAddConfiguredWindow(WindowPtr pWin, unsigned int valuemask) { unsigned int mask; - mask = valuemask & (CWParent | CWX | CWY | CWWidth | CWHeight | - CWBorderWidth | CWStackingOrder | CW_Map | CW_Update | CW_Shape); + mask = valuemask & (CWSibling | CWX | CWY | CWWidth | CWHeight | + CWBorderWidth | CWStackMode | CW_Map | CW_Update | CW_Shape); - valuemask &= ~(CWParent | CWX | CWY | CWWidth | CWHeight | CWBorderWidth | CWStackingOrder); + valuemask &= ~(CWSibling | CWX | CWY | CWWidth | CWHeight | CWBorderWidth | CWStackMode); if (mask & CWX && nxagentWindowPriv(pWin)->x != @@ -3612,11 +3612,11 @@ void nxagentAddConfiguredWindow(WindowPtr pWin, unsigned int valuemask) valuemask |= CWBorderWidth; } - if (mask & CWStackingOrder && + if (mask & CWStackMode && nxagentWindowPriv(pWin)->siblingAbove != nxagentWindowSiblingAbove(pWin)) { - valuemask |= CWStackingOrder; + valuemask |= CWStackMode; } { diff --git a/nx-X11/programs/Xserver/hw/nxagent/Windows.h b/nx-X11/programs/Xserver/hw/nxagent/Windows.h index 8612cdf82..35d686a33 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Windows.h +++ b/nx-X11/programs/Xserver/hw/nxagent/Windows.h @@ -159,9 +159,6 @@ extern int nxagentWindowPrivateIndex; #define nxagentDefaultWindowIsVisible() \ (nxagentVisibility != VisibilityFullyObscured) -#define CWParent CWSibling -#define CWStackingOrder CWStackMode - #define CW_Map (1 << 15) #define CW_Update (1 << 16) #define CW_Shape (1 << 17) -- cgit v1.2.3 From 3900ba3f8459c4822eaa6b8ac6035980a63fdfff Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Wed, 1 May 2019 10:40:47 +0200 Subject: NXshm.c: remove left-overs from patch format was broken, would not compile --- nx-X11/programs/Xserver/hw/nxagent/NXshm.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'nx-X11/programs/Xserver/hw') diff --git a/nx-X11/programs/Xserver/hw/nxagent/NXshm.c b/nx-X11/programs/Xserver/hw/nxagent/NXshm.c index 246d39355..9a314391c 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/NXshm.c +++ b/nx-X11/programs/Xserver/hw/nxagent/NXshm.c @@ -387,8 +387,8 @@ ProcShmPutImage(client) ((stuff->format != ZPixmap) && (stuff->srcX < screenInfo.bitmapScanlinePad) && ((stuff->format == XYBitmap) || - - ((stuff->srcY == 0) && - - (stuff->srcHeight == stuff->totalHeight))))) && + ((stuff->srcY == 0) && + (stuff->srcHeight == stuff->totalHeight))))) && ((stuff->srcX + stuff->srcWidth) == stuff->totalWidth)) (*pGC->ops->PutImage) (pDraw, pGC, stuff->depth, stuff->dstX, stuff->dstY, @@ -396,7 +396,7 @@ ProcShmPutImage(client) stuff->srcX, stuff->format, shmdesc->addr + stuff->offset + (stuff->srcY * length)); -- else + else #endif { #ifdef TEST -- cgit v1.2.3 From 1a8de6352d068e0a45904cf9b80bde30561eca2f Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Thu, 30 May 2019 00:30:46 +0200 Subject: dix/window.c: fix compiler warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Window.c:3827:46: warning: array subscript 128 is above array bounds of ‘StoringPixmapRec *[128]’ {aka ‘struct *[128]’} [-Warray-bounds] i, (void *) nxagentBSPixmapList[i]); --- nx-X11/programs/Xserver/hw/nxagent/Window.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'nx-X11/programs/Xserver/hw') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Window.c b/nx-X11/programs/Xserver/hw/nxagent/Window.c index f602d0ed3..6758e0875 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Window.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Window.c @@ -3938,16 +3938,16 @@ int nxagentEmptyBSPixmapList(void) StoringPixmapPtr nxagentFindItemBSPixmapList(unsigned long pixmapId) { - int i; - - for (i = 0; i < BSPIXMAPLIMIT; i++) + for (int i = 0; i < BSPIXMAPLIMIT; i++) { if ((nxagentBSPixmapList[i] != NULL) && (nxagentBSPixmapList[i] -> storingPixmapId == pixmapId)) { #ifdef TEST - fprintf(stderr, "nxagentFindItemBSPixmapList: pixmapId [%lu].\n", pixmapId); - fprintf(stderr, "nxagentFindItemBSPixmapList: nxagentBSPixmapList[%d] -> storingPixmapId [%lu].\n", + fprintf(stderr, "%s: pixmapId [%lu].\n", __func__, pixmapId); + fprintf(stderr, "%s: nxagentBSPixmapList[%d] = [%p].\n", __func__, + i, (void *) nxagentBSPixmapList[i]); + fprintf(stderr, "%s: nxagentBSPixmapList[%d] -> storingPixmapId [%lu].\n", __func__, i, nxagentBSPixmapList[i] -> storingPixmapId); #endif @@ -3955,15 +3955,13 @@ StoringPixmapPtr nxagentFindItemBSPixmapList(unsigned long pixmapId) } } - #ifdef TEST - fprintf(stderr, "nxagentFindItemBSPixmapList: WARNING! Item not found.\n"); + #ifdef WARNING + fprintf(stderr, "%s: WARNING! Item not found.\n", __func__); #endif #ifdef TEST - fprintf(stderr, "nxagentFindItemBSPixmapList: Pixmap with id [%lu] not found.\n", + fprintf(stderr, "%s: Pixmap with id [%lu] not found.\n", __func__, pixmapId); - fprintf(stderr, "nxagentBSPixmapList[%d] = [%p].\n", - i, (void *) nxagentBSPixmapList[i]); #endif return NULL; -- cgit v1.2.3 From 1bfafc127c82b87bbb398bbd7c6984144c3fb3eb Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Thu, 30 May 2019 11:38:10 +0200 Subject: Window.c: add missing comment about nxagentConfiguredWindowList was in inital version of 6ce9fb5f2875754f97035d3338b3d0e1d20169ae but got lost during some rebasing/cherry-picking preceeding the pull request. --- nx-X11/programs/Xserver/hw/nxagent/Window.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'nx-X11/programs/Xserver/hw') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Window.c b/nx-X11/programs/Xserver/hw/nxagent/Window.c index 6758e0875..78a5081f0 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Window.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Window.c @@ -3470,6 +3470,12 @@ void nxagentSetTopLevelEventMask(WindowPtr pWin) } /* + * Run nxagentConfigureWindow() on all windows in + * nxagentConfiguredWindowList and move them from the list + * afterwards. The list will be empty then. + * + * This is also taking care of entries in nxagentExposeQueue that need + * to be synchronized with the real X server. */ void nxagentFlushConfigureWindow(void) { -- cgit v1.2.3 From 2b25eb3d2fb4b2a50c0c746dfe967cfb82e38e1c Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Wed, 12 Jun 2019 00:16:48 +0200 Subject: Pixmap.c: fix comment phrasing/spelling --- nx-X11/programs/Xserver/hw/nxagent/Pixmap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'nx-X11/programs/Xserver/hw') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Pixmap.c b/nx-X11/programs/Xserver/hw/nxagent/Pixmap.c index be154f9c2..676a0aebb 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Pixmap.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Pixmap.c @@ -1355,7 +1355,7 @@ Bool nxagentPixmapOnShadowDisplay(PixmapPtr pMap) /* FIXME: If the pixmap has a different depth from the window, the - XPutImage returns a BadMatch. For example this may happens if + XPutImage returns a BadMatch. For example this may happen if the Render extension is enabled. Can we fix this creating a new pixmap? */ @@ -1372,7 +1372,7 @@ FIXME: If the pixmap has a different depth from the window, the /* * If the framebuffer is updated continuously, the nxagent - * visualization become too much slow. + * visualization becomes much too slow. */ if ((GetTimeInMillis() - showTime) < 500) -- cgit v1.2.3 From 6d00a387fc138b575dfe9133d5120fa9cb6a3a45 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Wed, 12 Jun 2019 19:25:57 +0200 Subject: Rootless.c: improve TEST/WARN/DEBUG outout by adding [] around values as almost everywhere --- nx-X11/programs/Xserver/hw/nxagent/Rootless.c | 72 +++++++++++++-------------- 1 file changed, 36 insertions(+), 36 deletions(-) (limited to 'nx-X11/programs/Xserver/hw') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Rootless.c b/nx-X11/programs/Xserver/hw/nxagent/Rootless.c index 82ec14fe9..f50cd1295 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Rootless.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Rootless.c @@ -485,7 +485,7 @@ int nxagentExportProperty(pWin, property, type, format, mode, nUnits, value) { #ifdef TEST fprintf(stderr, "nxagentExportProperty: WARNING! Ignored ChangeProperty " - "on %swindow %lx property %s type %s nUnits %ld format %d\n", + "on %swindow [0x%lx] property [%s] type [%s] nUnits [%ld] format [%d]\n", nxagentWindowTopLevel(pWin) ? "toplevel " : "", nxagentWindow(pWin), validateString(propertyS), validateString(typeS), nUnits, format); #endif @@ -565,8 +565,8 @@ int nxagentExportProperty(pWin, property, type, format, mode, nUnits, value) propHints.flags &= ~IconPixmapHint; #ifdef WARNING - fprintf(stderr, "nxagentExportProperty: WARNING! Failed to look up icon pixmap %x from hint " - "exporting property %s type %s on window %p.\n", + fprintf(stderr, "nxagentExportProperty: WARNING! Failed to look up icon pixmap [0x%x] from hint " + "exporting property [%s] type [%s] on window [%p].\n", (unsigned int) wmHints.icon_pixmap, propertyS, typeS, (void *) pWin); #endif @@ -587,8 +587,8 @@ int nxagentExportProperty(pWin, property, type, format, mode, nUnits, value) propHints.flags &= ~IconWindowHint; #ifdef WARNING - fprintf(stderr, "nxagentExportProperty: WARNING! Failed to look up icon window %x from hint " - "exporting property %s type %s on window %p.\n", + fprintf(stderr, "nxagentExportProperty: WARNING! Failed to look up icon window [0x%x] from hint " + "exporting property [%s] type [%s] on window [%p].\n", (unsigned int) wmHints.icon_window, propertyS, typeS, (void *) pWin); #endif @@ -609,8 +609,8 @@ int nxagentExportProperty(pWin, property, type, format, mode, nUnits, value) propHints.flags &= ~IconMaskHint; #ifdef WARNING - fprintf(stderr, "nxagentExportProperty: WARNING! Failed to look up icon mask %x from hint " - "exporting property %s type %s on window %p.\n", + fprintf(stderr, "nxagentExportProperty: WARNING! Failed to look up icon mask [0x%x] from hint " + "exporting property [%s] type [%s] on window [%p].\n", (unsigned int) wmHints.icon_mask, propertyS, typeS, (void *) pWin); #endif @@ -631,8 +631,8 @@ int nxagentExportProperty(pWin, property, type, format, mode, nUnits, value) propHints.flags &= ~WindowGroupHint; #ifdef WARNING - fprintf(stderr, "nxagentExportProperty: WARNING! Failed to look up window group %x from hint " - "exporting property %s type %s on window %p.\n", + fprintf(stderr, "nxagentExportProperty: WARNING! Failed to look up window group [0x%x] from hint " + "exporting property [%s] type [%s] on window [%p].\n", (unsigned int) wmHints.window_group, propertyS, typeS, (void *) pWin); #endif @@ -650,7 +650,7 @@ int nxagentExportProperty(pWin, property, type, format, mode, nUnits, value) if (!atoms) { #ifdef WARNING - fprintf(stderr, "nxagentExportProperty: WARNING! malloc() failed for '%s'- bailing out.\n", typeS); + fprintf(stderr, "nxagentExportProperty: WARNING! malloc() failed for '[%s]'- bailing out.\n", typeS); #endif return False; } @@ -679,7 +679,7 @@ int nxagentExportProperty(pWin, property, type, format, mode, nUnits, value) if (atoms[j] == None) { #ifdef WARNING - fprintf(stderr, "nxagentExportProperty: WARNING! Failed to convert local atom %ld [%s].\n", + fprintf(stderr, "nxagentExportProperty: WARNING! Failed to convert local atom [%ld] [%s].\n", (long int) input[i], validateString(atomName)); #endif } @@ -708,7 +708,7 @@ int nxagentExportProperty(pWin, property, type, format, mode, nUnits, value) if (!wind) { #ifdef WARNING - fprintf(stderr, "nxagentExportProperty: WARNING! malloc() failed for '%s' - bailing out.\n", typeS); + fprintf(stderr, "nxagentExportProperty: WARNING! malloc() failed for '[%s]' - bailing out.\n", typeS); #endif return False; } @@ -728,8 +728,8 @@ int nxagentExportProperty(pWin, property, type, format, mode, nUnits, value) else { #ifdef WARNING - fprintf(stderr, "nxagentExportProperty: WARNING! Failed to look up window %ld " - "exporting property %s type %s on window %p.\n", + fprintf(stderr, "nxagentExportProperty: WARNING! Failed to look up window [%ld] " + "exporting property [%s] type [%s] on window [%p].\n", (long int) input[i], propertyS, typeS, (void *) pWin); #endif @@ -819,7 +819,7 @@ int nxagentExportProperty(pWin, property, type, format, mode, nUnits, value) { #ifdef TEST fprintf(stderr, "nxagentExportProperty: WARNING! Ignored ChangeProperty " - "on %swindow %x property %s type %s nUnits %ld format %d\n", + "on %swindow [0x%x] property [%s] type [%s] nUnits [%ld] format [%d]\n", nxagentWindowTopLevel(pWin) ? "toplevel " : "", nxagentWindow(pWin), validateString(propertyS), validateString(typeS), nUnits, format); @@ -866,7 +866,7 @@ void nxagentImportProperty(Window window, if (pWin == NULL) { #ifdef TEST - fprintf(stderr, "nxagentImportProperty: Failed to look up remote window %lx property [%ld] exiting.\n", + fprintf(stderr, "nxagentImportProperty: Failed to look up remote window [0x%lx] property [%ld] exiting.\n", window, property); #endif @@ -885,7 +885,7 @@ void nxagentImportProperty(Window window, } #ifdef TEST - fprintf(stderr, "nxagentImportProperty: Window %lx property [%ld]: %s\n", + fprintf(stderr, "nxagentImportProperty: Window [0x%lx] property [%ld]: [%s]\n", window, property, validateString(NameForAtom(propertyL))); #endif @@ -900,7 +900,7 @@ void nxagentImportProperty(Window window, if (buffer == NULL && (nitems > 0)) { #ifdef WARNING - fprintf(stderr, "nxagentImportProperty: Failed to retrieve remote property [%ld] %s on Window %ld\n", + fprintf(stderr, "nxagentImportProperty: Failed to retrieve remote property [%ld] [%s] on Window [%ld]\n", (long int) property, validateString(NameForAtom(propertyL)), (long int) window); #endif } @@ -956,8 +956,8 @@ void nxagentImportProperty(Window window, else if (wmState.icon) { #ifdef WARNING - fprintf(stderr, "nxagentImportProperty: WARNING! Failed to convert remote window %ld" - " importing property %ld of type WM_STATE", (long int) wmState.icon, + fprintf(stderr, "nxagentImportProperty: WARNING! Failed to convert remote window [%ld]" + " importing property [%ld] of type WM_STATE", (long int) wmState.icon, (long int) property); #endif } @@ -982,7 +982,7 @@ void nxagentImportProperty(Window window, #ifdef WARNING fprintf(stderr, "nxagentImportProperty: WARNING! Failed to look up remote icon " - "pixmap %d from hint importing property [%ld] type %s on window %p.\n", + "pixmap [%d] from hint importing property [%ld] type [%s] on window [%p].\n", (unsigned int) wmHints.icon_pixmap, (long int) property, typeS, (void *) pWin); #endif @@ -1003,7 +1003,7 @@ void nxagentImportProperty(Window window, #ifdef WARNING fprintf(stderr, "nxagentImportProperty: WARNING! Failed to look up remote icon " - "window %x from hint importing property [%ld] type %s on window %p.\n", + "window [0x%x] from hint importing property [%ld] type [%s] on window [%p].\n", (unsigned int) wmHints.icon_window, (long int) property, typeS, (void *) pWin); #endif @@ -1024,7 +1024,7 @@ void nxagentImportProperty(Window window, #ifdef WARNING fprintf(stderr, "nxagentImportProperty: WARNING! Failed to look up remote icon " - "mask %x from hint importing property [%ld] type %s on window %p.\n", + "mask [0x%x] from hint importing property [%ld] type [%s] on window [%p].\n", (unsigned int) wmHints.icon_mask, (long int) property, typeS, (void *) pWin); #endif } @@ -1044,7 +1044,7 @@ void nxagentImportProperty(Window window, #ifdef WARNING fprintf(stderr, "nxagentImportProperty: WARNING! Failed to look up remote window " - "group %x from hint importing property [%ld] type %s on window %p.\n", + "group [0x%x] from hint importing property [%ld] type [%s] on window [%p].\n", (unsigned int) wmHints.window_group, (long int) property, typeS, (void *) pWin); #endif @@ -1060,7 +1060,7 @@ void nxagentImportProperty(Window window, if (atoms == NULL) { #ifdef WARNING - fprintf(stderr, "nxagentImportProperty: WARNING! malloc() failed for '%s' - bailing out.\n", typeS); + fprintf(stderr, "nxagentImportProperty: WARNING! malloc() failed for '[%s]' - bailing out.\n", typeS); #endif return; @@ -1077,7 +1077,7 @@ void nxagentImportProperty(Window window, if (atoms[i] == None) { #ifdef WARNING - fprintf(stderr, "nxagentImportProperty: WARNING! Failed to convert remote atom %ld.\n", + fprintf(stderr, "nxagentImportProperty: WARNING! Failed to convert remote atom [%ld].\n", (long int) input[i]); #endif } @@ -1093,7 +1093,7 @@ void nxagentImportProperty(Window window, if (!wind) { #ifdef WARNING - fprintf(stderr, "nxagentImportProperty: WARNING! malloc() failed for '%s' - bailing out.\n", typeS); + fprintf(stderr, "nxagentImportProperty: WARNING! malloc() failed for '[%s]' - bailing out.\n", typeS); #endif return; @@ -1113,8 +1113,8 @@ void nxagentImportProperty(Window window, else { #ifdef WARNING - fprintf(stderr, "nxagentImportProperty: WARNING! Failed to look up remote window %lx " - "importing property [%ld] type %s on window %p.\n", + fprintf(stderr, "nxagentImportProperty: WARNING! Failed to look up remote window [0x%lx] " + "importing property [%ld] type [%s] on window [%p].\n", (long int) input[i], (long int) property, typeS, (void*)pWin); #endif @@ -1127,7 +1127,7 @@ void nxagentImportProperty(Window window, { #ifdef TEST fprintf(stderr, "nxagentImportProperty: ChangeProperty " - "on window %lx property [%ld] type %s nitems %ld format %d\n", + "on window [0x%lx] property [%ld] type [%s] nitems [%ld] format [%d]\n", window, property, typeS, nitems, format); #endif @@ -1138,7 +1138,7 @@ void nxagentImportProperty(Window window, { #ifdef TEST fprintf(stderr, "nxagentImportProperty: WARNING! Ignored ChangeProperty " - "on window %lx property [%ld] type %s ntems %ld format %d\n", + "on window [0x%lx] property [%ld] type [%s] ntems [%ld] format [%d]\n", window, property, validateString(typeS), nitems, format); #endif } @@ -1183,7 +1183,7 @@ void nxagentRemovePropertyFromList(void) struct nxagentPropertyRec *tmp = nxagentPropertyList.first; #ifdef TEST - fprintf(stderr, "nxagentRemovePropertyFromList: Property %ld on Window %lx to list, list size is %d.\n\n", + fprintf(stderr, "nxagentRemovePropertyFromList: Property [%ld] on Window [0x%lx] to list, list size is [%d].\n\n", nxagentPropertyList.first -> property, nxagentPropertyList.first -> window, nxagentPropertyList.size); #endif @@ -1220,8 +1220,8 @@ void nxagentAddPropertyToList(Atom property, WindowPtr pWin) } #ifdef TEST - fprintf(stderr, "nxagentAddPropertyToList: Adding record Property %ld - Window %lx[%p]" - "to list, list size is %d.\n", property, nxagentWindow(pWin), (void*) pWin, + fprintf(stderr, "nxagentAddPropertyToList: Adding record Property [%ld] - Window [0x%lx][%p]" + "to list, list size is [%d].\n", property, nxagentWindow(pWin), (void*) pWin, nxagentPropertyList.size); #endif @@ -1262,12 +1262,12 @@ Bool nxagentNotifyMatchChangeProperty(void *p) XPropertyEvent *X = p; #ifdef TEST - fprintf(stderr, "nxagentNotifyMatchChangeProperty: Property notify on window %lx property %ld.\n", + fprintf(stderr, "nxagentNotifyMatchChangeProperty: Property notify on window [0x%lx] property [%ld].\n", X -> window, X -> atom); if (first) { - fprintf(stderr, "nxagentNotifyMatchChangeProperty: First element on list is window %lx property %ld list size is %d.\n", + fprintf(stderr, "nxagentNotifyMatchChangeProperty: First element on list is window [0x%lx] property [%ld] list size is [%d].\n", first -> window, first -> property, nxagentPropertyList.size); } else -- cgit v1.2.3 From 0f8dbbab2a218269165f06de37db59b5a20f09ea Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Fri, 14 Jun 2019 00:14:17 +0200 Subject: Screen.c: correctly free stuff in nxagentCloseScreen fixes a memory leak: ==19074== 2 bytes in 1 blocks are definitely lost in loss record 8 of 313 ==19074== at 0x483577F: malloc (vg_replace_malloc.c:299) ==19074== by 0x1FD83D: fbAllocatePrivates (fballpriv.c:79) ==19074== by 0x20A666: fbSetupScreen (fbscreen.c:110) ==19074== by 0x20A666: fbScreenInit (fbscreen.c:300) ==19074== by 0x1DEA4C: nxagentOpenScreen (Screen.c:1356) ==19074== by 0x16D7F8: AddScreen (dispatch.c:4257) ==19074== by 0x1DA0CF: InitOutput (Init.c:397) ==19074== by 0x14DCC2: main (main.c:280) --- nx-X11/programs/Xserver/hw/nxagent/Screen.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'nx-X11/programs/Xserver/hw') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Screen.c b/nx-X11/programs/Xserver/hw/nxagent/Screen.c index 8568562c2..7d180da44 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Screen.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Screen.c @@ -2141,20 +2141,32 @@ Bool nxagentCloseScreen(ScreenPtr pScreen) fprintf(stderr, "running nxagentCloseScreen()\n"); #endif + /* + * We have called fbScreenInit() in nxagenOpenScreen, which in turn + * called fbOpenScreen. But we are not using the data as created by + * fbOpenScreen but have freed it and replaced by our own. So we free + * our own stuff here and take care that fbCloseScreen will not free + * them again. + */ + for (i = 0; i < pScreen->numDepths; i++) { free(pScreen->allowedDepths[i].vids); + pScreen->allowedDepths[i].vids = NULL; } + pScreen->numDepths = 0; + /* * Free the frame buffer. */ free(((PixmapPtr)pScreen -> devPrivate) -> devPrivate.ptr); + free(pScreen->devPrivate);pScreen->devPrivate = NULL; + free(pScreen->allowedDepths); pScreen->allowedDepths = NULL; + free(pScreen->visuals); pScreen->visuals = NULL; - free(pScreen->allowedDepths); - free(pScreen->visuals); - free(pScreen->devPrivate); + fbCloseScreen(pScreen); /* * Reset the geometry and alpha information -- cgit v1.2.3 From 3b06ad51d91ff2b9442f159cddf34ed03bc2dd35 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Mon, 17 Jun 2019 16:06:02 +0200 Subject: Screen.c: Fix: make sure RRCloseScreen is being called Fixes ArcticaProject/nx-libs#598 In nxagentOpenScreen we first initialized the RRExtension for the screen and then replaced pScreen->CloseScreen by nxagentCloseScreen. This resulted in RandR's RRCloseScreen (and any other CloseScreen procedure installed by extensions) being no longer called. Moving RandR init after configuring pScreen->CloseScreen ensures the correct calling cascade: RRCloseScreen -> nxagentCloseScreen ->fbCloseScreen (called explicitly by nxagentCloseScreen). Which in turn will fix this memory leak: ==9688== 328 (312 direct, 16 indirect) bytes in 1 blocks are definitely lost in loss record 271 of 319 ==9688== at 0x4837B65: calloc (vg_replace_malloc.c:752) ==9688== by 0x4ED2C6: RRScreenInit (randr.c:329) ==9688== by 0x1F2B18: nxagentInitRandRExtension (Extensions.c:122) ==9688== by 0x1DEAFF: nxagentOpenScreen (Screen.c:1409) ==9688== by 0x16D7F8: AddScreen (dispatch.c:4257) ==9688== by 0x1DA0CF: InitOutput (Init.c:397) ==9688== by 0x14DCC2: main (main.c:280) --- nx-X11/programs/Xserver/hw/nxagent/Screen.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'nx-X11/programs/Xserver/hw') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Screen.c b/nx-X11/programs/Xserver/hw/nxagent/Screen.c index 7d180da44..84ef9c4a4 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Screen.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Screen.c @@ -1401,13 +1401,6 @@ Bool nxagentOpenScreen(ScreenPtr pScreen, pScreen -> rootVisual = defaultVisual; pScreen -> rootDepth = rootDepth; - /* - * Complete the initialization of the RANDR - * extension. - */ - - nxagentInitRandRExtension(pScreen); - /* * Set up the internal structures used for * tracking the proxy resources associated @@ -1694,6 +1687,13 @@ N/A nxagentOption(Height)) / 32) } + /* + * Complete the initialization of the RANDR + * extension. + */ + + nxagentInitRandRExtension(pScreen); + #ifdef TEST nxagentPrintAgentGeometry(NULL, "nxagentOpenScreen:"); #endif -- cgit v1.2.3 From 340de78e26e7837561909ae2a44c2ef85863d87b Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Mon, 17 Jun 2019 17:31:32 +0200 Subject: Keyboard.c: nullify freed pointers While trying to properly free memory allocated by XKB I accidently called nxagentFreeKeyboardDeviceData twice and noticed it would cause a segfault here. As the other pointers are also nullified after being freed let's just do it here, too. --- nx-X11/programs/Xserver/hw/nxagent/Keyboard.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'nx-X11/programs/Xserver/hw') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Keyboard.c b/nx-X11/programs/Xserver/hw/nxagent/Keyboard.c index 96b33ea7d..46686b754 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Keyboard.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Keyboard.c @@ -1327,14 +1327,18 @@ static int nxagentFreeKeyboardDeviceData(DeviceIntPtr dev) dev->focus = NULL; } - for (k = dev->kbdfeed; k; k = knext) + if (dev->kbdfeed) { - knext = k->next; - #ifdef XKB - if (k->xkb_sli) - XkbFreeSrvLedInfo(k->xkb_sli); - #endif - free(k); + for (k = dev->kbdfeed; k; k = knext) + { + knext = k->next; + #ifdef XKB + if (k->xkb_sli) + XkbFreeSrvLedInfo(k->xkb_sli); + #endif + free(k); + } + dev->kbdfeed = NULL; } #ifdef DEBUG -- cgit v1.2.3 From 4dd1f3cbdff984ff55bc2f88c64b2544c8d88148 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Mon, 17 Jun 2019 20:25:09 +0200 Subject: Fix memleaks: Free devPrivates of devices on shutdown Fixes these two memory leaks identified by valgrind: ==28336== 32 (8 direct, 24 indirect) bytes in 1 blocks are definitely lost in loss record 180 of 308 ==28336== at 0x48356AF: malloc (vg_replace_malloc.c:298) ==28336== by 0x4837DE7: realloc (vg_replace_malloc.c:826) ==28336== by 0x1AE322: AllocateDevicePrivate (privates.c:439) ==28336== by 0x27527B: XkbSetExtension (xkbActions.c:72) ==28336== by 0x198E9B: _RegisterPointerDevice (devices.c:361) ==28336== by 0x1DBA35: InitInput (Init.c:440) ==28336== by 0x14DBD6: main (main.c:303) ==28336== ==28336== 32 (8 direct, 24 indirect) bytes in 1 blocks are definitely lost in loss record 181 of 308 ==28336== at 0x48356AF: malloc (vg_replace_malloc.c:298) ==28336== by 0x4837DE7: realloc (vg_replace_malloc.c:826) ==28336== by 0x1AE322: AllocateDevicePrivate (privates.c:439) ==28336== by 0x27527B: XkbSetExtension (xkbActions.c:72) ==28336== by 0x198F1B: _RegisterKeyboardDevice (devices.c:384) ==28336== by 0x1DBA3D: InitInput (Init.c:441) ==28336== by 0x14DBD6: main (main.c:303) --- nx-X11/programs/Xserver/hw/nxagent/Keyboard.c | 9 ++++++++- nx-X11/programs/Xserver/hw/nxagent/Pointer.c | 11 +++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) (limited to 'nx-X11/programs/Xserver/hw') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Keyboard.c b/nx-X11/programs/Xserver/hw/nxagent/Keyboard.c index 46686b754..c8038955b 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Keyboard.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Keyboard.c @@ -1025,11 +1025,18 @@ Reply Total Cached Bits In Bits Out Bits/Reply Ratio break; case DEVICE_CLOSE: - #ifdef TEST fprintf(stderr, "nxagentKeyboardProc: Called for [DEVICE_CLOSE].\n"); #endif + for (int i = 0; i < pDev->nPrivates; i++) + { + free(pDev->devPrivates[i].ptr); + pDev->devPrivates[i].ptr = NULL; + } + free(pDev->devPrivates); + pDev->devPrivates = NULL; + break; } diff --git a/nx-X11/programs/Xserver/hw/nxagent/Pointer.c b/nx-X11/programs/Xserver/hw/nxagent/Pointer.c index c59230724..85d286b96 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Pointer.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Pointer.c @@ -40,7 +40,7 @@ is" without express or implied warranty. #include "X.h" #include "Xproto.h" #include "screenint.h" -#include "input.h" +#include "inputstr.h" #include "misc.h" #include "scrnintstr.h" #include "servermd.h" @@ -162,11 +162,18 @@ int nxagentPointerProc(DeviceIntPtr pDev, int onoff) break; case DEVICE_CLOSE: - #ifdef TEST fprintf(stderr, "nxagentPointerProc: Called for [DEVICE_CLOSE].\n"); #endif + for (int i = 0; i < pDev->nPrivates; i++) + { + free(pDev->devPrivates[i].ptr); + pDev->devPrivates[i].ptr = NULL; + } + free(pDev->devPrivates); + pDev->devPrivates = NULL; + break; } -- cgit v1.2.3 From 7564422263a10ec8992e538bb741b2ddb51dad82 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Mon, 17 Jun 2019 23:37:51 +0200 Subject: Screen.c: fix another memory leak ==12280== 0 bytes in 5 blocks are definitely lost in loss record 1 of 304 ==12280== at 0x483577F: malloc (vg_replace_malloc.c:299) ==12280== by 0x2EFC29: init_visuals (xf86glx.c:489) ==12280== by 0x2EFC29: __MESA_initVisuals (xf86glx.c:540) ==12280== by 0x17C902: GlxInitVisuals (glxext.c:317) ==12280== by 0x218C03: fbInitVisuals (fbcmap.c:668) ==12280== by 0x20BC41: fbFinishScreenInit (fbscreen.c:229) ==12280== by 0x20C005: fbScreenInit (fbscreen.c:273) ==12280== by 0x1E024C: nxagentOpenScreen (Screen.c:1356) ==12280== by 0x16D828: AddScreen (dispatch.c:4171) ==12280== by 0x1DB7DF: InitOutput (Init.c:396) ==12280== by 0x14DB12: main (main.c:279) ==12280== ==12280== 64 bytes in 2 blocks are definitely lost in loss record 223 of 304 ==12280== at 0x483577F: malloc (vg_replace_malloc.c:299) ==12280== by 0x2EFA05: init_visuals (xf86glx.c:489) ==12280== by 0x2EFA05: __MESA_initVisuals (xf86glx.c:540) ==12280== by 0x17C902: GlxInitVisuals (glxext.c:317) ==12280== by 0x218C03: fbInitVisuals (fbcmap.c:668) ==12280== by 0x20BC41: fbFinishScreenInit (fbscreen.c:229) ==12280== by 0x20C005: fbScreenInit (fbscreen.c:273) ==12280== by 0x1E024C: nxagentOpenScreen (Screen.c:1356) ==12280== by 0x16D828: AddScreen (dispatch.c:4171) ==12280== by 0x1DB7DF: InitOutput (Init.c:396) ==12280== by 0x14DB12: main (main.c:279) --- nx-X11/programs/Xserver/hw/nxagent/Screen.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'nx-X11/programs/Xserver/hw') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Screen.c b/nx-X11/programs/Xserver/hw/nxagent/Screen.c index 84ef9c4a4..2fcb741db 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Screen.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Screen.c @@ -1391,15 +1391,23 @@ Bool nxagentOpenScreen(ScreenPtr pScreen, * by fbScreenInit with our own. */ - free(pScreen -> visuals); + for (int i = 0; i < pScreen->numDepths; i++) + { + #ifdef DEBUG + fprintf(stderr, "%s: depth [%d] index [%d] vids [%p]\n", __func__, pScreen->allowedDepths[i].depth, i, (void*) pScreen->allowedDepths[i].vids); + #endif + free(pScreen->allowedDepths[i].vids); + } + free(pScreen -> allowedDepths); + pScreen -> allowedDepths = depths; + pScreen -> numDepths = numDepths; + pScreen -> rootDepth = rootDepth; + free(pScreen -> visuals); pScreen -> visuals = visuals; - pScreen -> allowedDepths = depths; pScreen -> numVisuals = numVisuals; - pScreen -> numDepths = numDepths; pScreen -> rootVisual = defaultVisual; - pScreen -> rootDepth = rootDepth; /* * Set up the internal structures used for -- cgit v1.2.3 From 17d5e62ba400e105b7faf130ef31db299a5478c7 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Mon, 17 Jun 2019 21:57:45 +0200 Subject: Events.c: use designated initializer in nxagentDeactivatePointerGrab --- nx-X11/programs/Xserver/hw/nxagent/Events.c | 32 +++++++++++++++-------------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'nx-X11/programs/Xserver/hw') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Events.c b/nx-X11/programs/Xserver/hw/nxagent/Events.c index 4bddbba3a..8e976779d 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Events.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Events.c @@ -4011,21 +4011,23 @@ void nxagentDeactivatePointerGrab(void) if (grab) { - XButtonEvent X; - memset(&X, 0, sizeof(XButtonEvent)); - - X.type = ButtonRelease; - X.serial = 0; - X.send_event = FALSE; - X.time = currentTime.milliseconds; - X.display = nxagentDisplay; - X.window = nxagentWindow(grab -> window); - X.root = RootWindow(nxagentDisplay, 0); - X.subwindow = 0; - X.x = X.y = X.x_root = X.y_root = 0; - X.state = 0x100; - X.button = 1; - X.same_screen = TRUE; + XButtonEvent X = { + .type = ButtonRelease, + .serial = 0, + .send_event = FALSE, + .time = currentTime.milliseconds, + .display = nxagentDisplay, + .window = nxagentWindow(grab -> window), + .root = RootWindow(nxagentDisplay, 0), + .subwindow = 0, + .x = 0, + .y = 0, + .x_root = 0, + .y_root = 0, + .state = 0x100, + .button = 1, + .same_screen = TRUE, + }; XPutBackEvent(nxagentDisplay, (XEvent*)&X); } -- cgit v1.2.3 From 7e12c9ba57eb583cf1d0a22894fa3c4c090a2c7f Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Tue, 18 Jun 2019 19:04:12 +0200 Subject: Extension.c: code simplifications --- nx-X11/programs/Xserver/hw/nxagent/Extensions.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'nx-X11/programs/Xserver/hw') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Extensions.c b/nx-X11/programs/Xserver/hw/nxagent/Extensions.c index 785724cea..239d84b85 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Extensions.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Extensions.c @@ -98,13 +98,12 @@ void nxagentInitGlxExtension(VisualPtr *visuals, DepthPtr *depths, int *numVisuals, int *numDepths, int *rootDepth, VisualID *defaultVisual) { - miInitVisualsProcPtr initVisuals; /* * Initialize the visuals to use the GLX extension. */ - initVisuals = NULL; + miInitVisualsProcPtr initVisuals = NULL; GlxWrapInitVisuals(&initVisuals); @@ -372,15 +371,13 @@ static int nxagentRandRInitSizes(ScreenPtr pScreen) int nxagentRandRSetConfig(ScreenPtr pScreen, Rotation rotation, int rate, RRScreenSizePtr pSize) { - int r; - UpdateCurrentTime(); /* * Whatever size is OK for us. */ - r = nxagentResizeScreen(pScreen, pSize -> width, pSize -> height, + int r = nxagentResizeScreen(pScreen, pSize -> width, pSize -> height, pSize -> mmWidth, pSize -> mmHeight); nxagentMoveViewport(pScreen, 0, 0); @@ -430,8 +427,6 @@ void nxagentRandRSetWindowsSize(int width, int height) int nxagentRandRScreenSetSize(ScreenPtr pScreen, CARD16 width, CARD16 height, CARD32 mmWidth, CARD32 mmHeight) { - int result; - UpdateCurrentTime(); if (nxagentOption(DesktopResize) == 1 && @@ -453,7 +448,7 @@ int nxagentRandRScreenSetSize(ScreenPtr pScreen, CARD16 width, CARD16 height, nxagentChangeOption(Height, height); } - result = nxagentResizeScreen(pScreen, width, height, mmWidth, mmHeight); + int result = nxagentResizeScreen(pScreen, width, height, mmWidth, mmHeight); if (result == 1 && nxagentOption(DesktopResize) == 1 && nxagentOption(Fullscreen) == 0 && nxagentOption(AllScreens) == 0) -- cgit v1.2.3 From b5eb7c76e9758973a84a060d47b044f2acc980d3 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Tue, 18 Jun 2019 19:10:38 +0200 Subject: Screen.c: more debug output --- nx-X11/programs/Xserver/hw/nxagent/Screen.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'nx-X11/programs/Xserver/hw') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Screen.c b/nx-X11/programs/Xserver/hw/nxagent/Screen.c index 2fcb741db..b5d133b42 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Screen.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Screen.c @@ -1394,7 +1394,7 @@ Bool nxagentOpenScreen(ScreenPtr pScreen, for (int i = 0; i < pScreen->numDepths; i++) { #ifdef DEBUG - fprintf(stderr, "%s: depth [%d] index [%d] vids [%p]\n", __func__, pScreen->allowedDepths[i].depth, i, (void*) pScreen->allowedDepths[i].vids); + fprintf(stderr, "%s: freeing depth [%d] index [%d] vids [%p]\n", __func__, pScreen->allowedDepths[i].depth, i, (void*) pScreen->allowedDepths[i].vids); #endif free(pScreen->allowedDepths[i].vids); } @@ -2159,6 +2159,9 @@ Bool nxagentCloseScreen(ScreenPtr pScreen) for (i = 0; i < pScreen->numDepths; i++) { + #ifdef DEBUG + fprintf(stderr, "%s: freeing depth [%d] index [%d] vids [%p]\n", __func__, pScreen->allowedDepths[i].depth, i, (void*) pScreen->allowedDepths[i].vids); + #endif free(pScreen->allowedDepths[i].vids); pScreen->allowedDepths[i].vids = NULL; } -- cgit v1.2.3 From cb508b2632f661e19b44f1375ddce3ffb415f4c5 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Sat, 25 May 2019 19:38:14 +0200 Subject: various scope improvements --- nx-X11/programs/Xserver/hw/nxagent/Events.c | 24 +++++-------- nx-X11/programs/Xserver/hw/nxagent/Font.c | 49 +++++++++----------------- nx-X11/programs/Xserver/hw/nxagent/Keyboard.c | 4 +-- nx-X11/programs/Xserver/hw/nxagent/NXglyph.c | 8 +---- nx-X11/programs/Xserver/hw/nxagent/NXpicture.c | 12 ++----- nx-X11/programs/Xserver/hw/nxagent/Pixmap.c | 18 ++++------ nx-X11/programs/Xserver/hw/nxagent/Rootless.c | 38 +++++++------------- nx-X11/programs/Xserver/hw/nxagent/Screen.c | 4 +-- 8 files changed, 50 insertions(+), 107 deletions(-) (limited to 'nx-X11/programs/Xserver/hw') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Events.c b/nx-X11/programs/Xserver/hw/nxagent/Events.c index 8e976779d..9d9f5d204 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Events.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Events.c @@ -1964,14 +1964,14 @@ FIXME: Don't enqueue the KeyRelease event if the key was } case UnmapNotify: { - WindowPtr pWin; - #ifdef TEST fprintf(stderr, "nxagentDispatchEvents: Going to handle new UnmapNotify event.\n"); #endif if (nxagentOption(Rootless) == 1) { + WindowPtr pWin; + if ((pWin = nxagentRootlessTopLevelWindow(X.xunmap.window)) != NULL || ((pWin = nxagentWindowPtr(X.xunmap.window)) != NULL && nxagentWindowTopLevel(pWin) == 1)) @@ -1995,22 +1995,19 @@ FIXME: Don't enqueue the KeyRelease event if the key was } case MapNotify: { - WindowPtr pWin; - ClientPtr pClient; - #ifdef TEST fprintf(stderr, "nxagentDispatchEvents: Going to handle new MapNotify event.\n"); #endif if (nxagentOption(Rootless) == 1) { - Bool value = 1; + WindowPtr pWin; if ((pWin = nxagentRootlessTopLevelWindow(X.xmap.window)) != NULL || ((pWin = nxagentWindowPtr(X.xmap.window)) != NULL && nxagentWindowTopLevel(pWin) == 1)) { - pClient = wClient(pWin); + ClientPtr pClient = wClient(pWin); nxagentScreenTrap = 1; @@ -2021,6 +2018,8 @@ FIXME: Don't enqueue the KeyRelease event if the key was if (pWin != NULL) { + Bool value = 1; + TraverseTree(pWin, nxagentChangeMapPrivate, &value); } } @@ -2355,8 +2354,6 @@ int nxagentHandleKeyPress(XEvent *X, enum HandleEventResult *result) int nxagentHandlePropertyNotify(XEvent *X) { - int resource; - if (nxagentOption(Rootless) && !nxagentNotifyMatchChangeProperty((XPropertyEvent *) X)) { #ifdef TEST @@ -2366,7 +2363,7 @@ int nxagentHandlePropertyNotify(XEvent *X) if (nxagentWindowPtr(X -> xproperty.window) != NULL) { - resource = NXGetCollectPropertyResource(nxagentDisplay); + int resource = NXGetCollectPropertyResource(nxagentDisplay); if (resource == -1) { @@ -2643,8 +2640,6 @@ int nxagentHandleGraphicsExposeEvent(XEvent *X) int nxagentHandleClientMessageEvent(XEvent *X, enum HandleEventResult *result) { - WindowPtr pWin; - *result = doNothing; #ifdef TEST @@ -2680,7 +2675,7 @@ int nxagentHandleClientMessageEvent(XEvent *X, enum HandleEventResult *result) return 0; } - pWin = nxagentWindowPtr(X -> xclient.window); + WindowPtr pWin = nxagentWindowPtr(X -> xclient.window); if (pWin == NULL) { @@ -2886,7 +2881,6 @@ int nxagentHandleXkbKeyboardStateEvent(XEvent *X) int nxagentHandleXFixesSelectionNotify(XEvent *X) { - int i; Atom local; XFixesSelectionEvent *xfixesEvent = (XFixesSelectionEvent *) X; @@ -2915,7 +2909,7 @@ int nxagentHandleXFixesSelectionNotify(XEvent *X) if (SelectionCallback) { - i = 0; + int i = 0; while ((i < NumCurrentSelections) && CurrentSelections[i].selection != local) diff --git a/nx-X11/programs/Xserver/hw/nxagent/Font.c b/nx-X11/programs/Xserver/hw/nxagent/Font.c index 8de50fdc3..c135adb72 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Font.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Font.c @@ -165,8 +165,6 @@ static struct _nxagentFailedToReconnectFonts void nxagentFreeFontCache(void) { - int i; - #ifdef NXAGENT_FONTCACHE_DEBUG fprintf(stderr, "Font: Freeing nxagent font cache\n"); #endif @@ -178,7 +176,7 @@ void nxagentFreeFontCache(void) fprintf(stderr, "Font: Freeing nxagent font cache, there are [%d] entries.\n", CACHE_INDEX); #endif - for (i = 0; i < CACHE_INDEX; i++) + for (int i = 0; i < CACHE_INDEX; i++) { #ifdef NXAGENT_FONTCACHE_DEBUG fprintf(stderr, "Font: Freeing nxagent font cache entry [%d] entry pointer is [%p], name [%s]\n", @@ -208,8 +206,6 @@ void nxagentFreeFontCache(void) void nxagentListRemoteFonts(const char *searchPattern, const int maxNames) { - int i, q, p; - char **xList; int xLen = 0; @@ -241,7 +237,7 @@ void nxagentListRemoteFonts(const char *searchPattern, const int maxNames) * other one will select the 'real' fonts. */ - for (p = 0; p < patternsQt; p++) + for (int p = 0; p < patternsQt; p++) { xList = XListFonts(nxagentDisplay, patterns[p], maxNames, &xLen); @@ -256,11 +252,9 @@ void nxagentListRemoteFonts(const char *searchPattern, const int maxNames) nxagentListRemoteAddName(searchPattern, maxNames); - for (i = 0; i < xLen; i++) + for (int i = 0; i < xLen; i++) { - q = 1; - - nxagentListRemoteAddName(xList[i], q); + nxagentListRemoteAddName(xList[i], 1); } XFreeFontNames(xList); @@ -270,7 +264,7 @@ void nxagentListRemoteFonts(const char *searchPattern, const int maxNames) fprintf(stderr, "nxagentListRemoteFonts: Printing remote font list.\n"); - for (i = 0; i < nxagentRemoteFontList.length; i++) + for (int i = 0; i < nxagentRemoteFontList.length; i++) { fprintf(stderr, "Font# %d, \"%s\"\n", i, nxagentRemoteFontList.list[i]->name); } @@ -353,9 +347,7 @@ void nxagentListRemoteAddName(const char *name, int status) static void nxagentFreeRemoteFontList(nxagentFontList *listRec) { - int l; - - for (l = 0; l < listRec -> length; l++) + for (int l = 0; l < listRec -> length; l++) { if (listRec -> list[l]) { @@ -857,7 +849,6 @@ static void nxagentFontDisconnect(FontPtr pFont, XID param1, void * param2) { nxagentPrivFont *privFont; Bool *pBool = (Bool*)param2; - int i; if (pFont == NULL || !*pBool) return; @@ -869,7 +860,7 @@ static void nxagentFontDisconnect(FontPtr pFont, XID param1, void * param2) (void *) pFont, privFont -> font_struct ? nxagentFont(pFont) : 0); #endif - for (i = 0; i < CACHE_INDEX; i++) + for (int i = 0; i < CACHE_INDEX; i++) { if (strcasecmp(CACHE_NAME(i), privFont -> fontName) == 0) { @@ -1043,13 +1034,11 @@ static void nxagentFontReconnect(FontPtr pFont, XID param1, void * param2) static void nxagentFreeCacheBeforeReconnect(void) { - int i; - #ifdef NXAGENT_RECONNECT_FONT_DEBUG printFontCacheDump("nxagentFreeCacheBeforeReconnect"); #endif - for (i = 0; i < CACHE_INDEX; i++) + for (int i = 0; i < CACHE_INDEX; i++) { if (CACHE_FSTRUCT(i)) { @@ -1061,15 +1050,13 @@ static void nxagentFreeCacheBeforeReconnect(void) static void nxagentCleanCacheAfterReconnect(void) { - int i, j; int real_size = CACHE_INDEX; - nxCacheFontEntryRecPtr swapEntryPtr; #ifdef NXAGENT_RECONNECT_FONT_DEBUG printFontCacheDump("nxagentCleanCacheAfterReconnect"); #endif - for (i = 0; i < CACHE_INDEX; i++) + for (int i = 0; i < CACHE_INDEX; i++) { if(CACHE_FSTRUCT(i) == NULL) { @@ -1078,8 +1065,11 @@ static void nxagentCleanCacheAfterReconnect(void) } } - for (i = 0; i < real_size; i++) + for (int i = 0; i < real_size; i++) { + int j; + nxCacheFontEntryRecPtr swapEntryPtr; + /* Find - first bad occurrence if exist. */ while ((i < real_size) && CACHE_FSTRUCT(i)) i++; @@ -1108,11 +1098,9 @@ static void nxagentCleanCacheAfterReconnect(void) #ifdef NXAGENT_RECONNECT_FONT_DEBUG static void printFontCacheDump(char* msg) { - int i; - fprintf(stderr, "%s - begin -\n", msg); - for (i = 0; i < CACHE_INDEX; i++) + for (int i = 0; i < CACHE_INDEX; i++) { if (CACHE_FSTRUCT(i)) { @@ -1129,7 +1117,6 @@ static void printFontCacheDump(char* msg) Bool nxagentReconnectAllFonts(void *p0) { - int cid; Bool fontSuccess = True; reconnectFlexibility = *((int *) p0); @@ -1147,7 +1134,7 @@ Bool nxagentReconnectAllFonts(void *p0) FindClientResourcesByType(clients[serverClient -> index], RT_NX_FONT, (FindResType) nxagentFontReconnect, &fontSuccess); - for (cid = 0; cid < MAXCLIENTS; cid++) + for (int cid = 0; cid < MAXCLIENTS; cid++) { if (clients[cid]) { @@ -1258,7 +1245,6 @@ static void nxagentFreeFailedToReconnectFonts(void) Bool nxagentReconnectFailedFonts(void *p0) { - int i; int attempt = 1; const int maxAttempt = 5; @@ -1312,7 +1298,7 @@ Bool nxagentReconnectFailedFonts(void *p0) nxagentFreeRemoteFontList(&nxagentRemoteFontList); nxagentListRemoteFonts("*", nxagentMaxFontNames); - for(i = 0; i < nxagentFailedToReconnectFonts.index; i++) + for(int i = 0; i < nxagentFailedToReconnectFonts.index; i++) { fontSuccess = True; @@ -1365,7 +1351,6 @@ Bool nxagentReconnectFailedFonts(void *p0) Bool nxagentDisconnectAllFonts(void) { - int cid; Bool fontSuccess = True; #if defined(NXAGENT_RECONNECT_DEBUG) || defined(NXAGENT_RECONNECT_FONT_DEBUG) @@ -1384,7 +1369,7 @@ Bool nxagentDisconnectAllFonts(void) FindClientResourcesByType(clients[serverClient -> index], RT_NX_FONT, (FindResType) nxagentFontDisconnect, &fontSuccess); - for(cid = 0; cid < MAXCLIENTS; cid++) + for(int cid = 0; cid < MAXCLIENTS; cid++) { if( clients[cid] && fontSuccess ) { diff --git a/nx-X11/programs/Xserver/hw/nxagent/Keyboard.c b/nx-X11/programs/Xserver/hw/nxagent/Keyboard.c index c8038955b..cff92ec48 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Keyboard.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Keyboard.c @@ -1299,8 +1299,6 @@ static int nxagentRestoreKeyboardDeviceData(DeviceIntPtr devBackup, DeviceIntPtr static int nxagentFreeKeyboardDeviceData(DeviceIntPtr dev) { - KbdFeedbackPtr k, knext; - if (!dev) { #ifdef PANIC @@ -1336,7 +1334,7 @@ static int nxagentFreeKeyboardDeviceData(DeviceIntPtr dev) if (dev->kbdfeed) { - for (k = dev->kbdfeed; k; k = knext) + for (KbdFeedbackPtr k = dev->kbdfeed, knext; k; k = knext) { knext = k->next; #ifdef XKB diff --git a/nx-X11/programs/Xserver/hw/nxagent/NXglyph.c b/nx-X11/programs/Xserver/hw/nxagent/NXglyph.c index 35dcbc132..1f82e73dc 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/NXglyph.c +++ b/nx-X11/programs/Xserver/hw/nxagent/NXglyph.c @@ -138,12 +138,6 @@ ResizeGlyphHash (GlyphHashPtr hash, CARD32 change, Bool global) int oldSize; CARD32 s; - #ifdef NXAGENT_SERVER - - CARD32 c; - - #endif - tableEntries = hash->tableEntries + change; hashSet = FindGlyphHashSet (tableEntries); if (hashSet == hash->hashSet) @@ -164,7 +158,7 @@ ResizeGlyphHash (GlyphHashPtr hash, CARD32 change, Bool global) #ifdef NXAGENT_SERVER - c = hash->table[i].corruptedGlyph; + CARD32 c = hash->table[i].corruptedGlyph; #endif diff --git a/nx-X11/programs/Xserver/hw/nxagent/NXpicture.c b/nx-X11/programs/Xserver/hw/nxagent/NXpicture.c index 4ea7d2d73..e35d1e9bc 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/NXpicture.c +++ b/nx-X11/programs/Xserver/hw/nxagent/NXpicture.c @@ -309,12 +309,6 @@ static PicturePtr createSourcePicture(void) unsigned int totalPictureSize; - DevUnion *ppriv; - - char *privPictureRecAddr; - - int i; - /* * Compute size of entire PictureRect, plus privates. */ @@ -327,9 +321,9 @@ static PicturePtr createSourcePicture(void) if (pPicture != NULL) { - ppriv = (DevUnion *) (pPicture + 1); + DevUnion *ppriv = (DevUnion *) (pPicture + 1); - for (i = 0; i < picturePrivateCount; ++i) + for (int i = 0; i < picturePrivateCount; ++i) { /* * Other privates are inaccessible. @@ -338,7 +332,7 @@ static PicturePtr createSourcePicture(void) ppriv[i].ptr = NULL; } - privPictureRecAddr = (char *) &ppriv[picturePrivateCount]; + char *privPictureRecAddr = (char *) &ppriv[picturePrivateCount]; ppriv[nxagentPicturePrivateIndex].ptr = (void *) privPictureRecAddr; diff --git a/nx-X11/programs/Xserver/hw/nxagent/Pixmap.c b/nx-X11/programs/Xserver/hw/nxagent/Pixmap.c index 676a0aebb..653426ebb 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Pixmap.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Pixmap.c @@ -700,7 +700,6 @@ static void nxagentPixmapMatchID(void *p0, XID x1, void *p2) PixmapPtr nxagentPixmapPtr(Pixmap pixmap) { - int i; struct nxagentPixmapPair pair; if (pixmap == None) @@ -714,7 +713,7 @@ PixmapPtr nxagentPixmapPtr(Pixmap pixmap) FindClientResourcesByType(clients[serverClient -> index], RT_NX_PIXMAP, nxagentPixmapMatchID, &pair); - for (i = 0; (pair.pMap == NULL) && (i < MAXCLIENTS); i++) + for (int i = 0; (pair.pMap == NULL) && (i < MAXCLIENTS); i++) { if (clients[i]) { @@ -790,8 +789,8 @@ void nxagentDisconnectPixmap(void *p0, XID x1, void *p2) Bool nxagentDisconnectAllPixmaps(void) { - int r = 1; int i; + int r = 1; #ifdef TEST fprintf(stderr, "nxagentDisconnectAllPixmaps: Going to iterate through pixmap resources.\n"); @@ -958,8 +957,6 @@ Bool nxagentReconnectAllPixmaps(void *p0) { Bool result = 1; - int i; - #ifdef TEST fprintf(stderr, "nxagentReconnectAllPixmaps: Going to recreate all pixmaps.\n"); #endif @@ -991,7 +988,7 @@ Bool nxagentReconnectAllPixmaps(void *p0) #endif - for (i = 0, result = 1; i < MAXCLIENTS; result = 1, i++) + for (int i = 0, result = 1; i < MAXCLIENTS; result = 1, i++) { if (clients[i] != NULL) { @@ -1138,10 +1135,9 @@ Bool nxagentCheckPixmapIntegrity(PixmapPtr pPixmap) if (!integrity) { - int i; char *p, *q; - for (i = 0, p = image -> data, q = data; i < length; i++) + for (int i = 0, p = image -> data, q = data; i < length; i++) { if (p[i] != q[i]) { @@ -1187,7 +1183,6 @@ Bool nxagentCheckPixmapIntegrity(PixmapPtr pPixmap) Bool nxagentCheckAllPixmapIntegrity(void) { - int i; Bool imageIsGood = True; #ifdef TEST @@ -1197,7 +1192,7 @@ Bool nxagentCheckAllPixmapIntegrity(void) FindClientResourcesByType(clients[serverClient -> index], RT_NX_PIXMAP, nxagentCheckOnePixmapIntegrity, &imageIsGood); - for (i = 0; (i < MAXCLIENTS) && (imageIsGood); i++) + for (int i = 0; (i < MAXCLIENTS) && (imageIsGood); i++) { if (clients[i]) { @@ -1630,11 +1625,10 @@ void nxagentPrintResourcePredicate(void *value, XID id, XID type, void *cdata) void nxagentPrintResources(void) { Bool result; - int i; nxagentPrintResourceTypes(); - for (i = 0; i < MAXCLIENTS; i++) + for (int i = 0; i < MAXCLIENTS; i++) { if (clients[i]) { diff --git a/nx-X11/programs/Xserver/hw/nxagent/Rootless.c b/nx-X11/programs/Xserver/hw/nxagent/Rootless.c index f50cd1295..c2611c194 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Rootless.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Rootless.c @@ -120,12 +120,10 @@ static void nxagentPrintRootlessTopLevelWindowMap(void); void nxagentPrintRootlessTopLevelWindowMap(void) { - int i; - fprintf(stderr, "nxagentPrintRootlessTopLevelWindowMap: Map size is [%d] num of entry [%d].\n", topLevelParentMap.size, topLevelParentMap.next); - for (i = 0; i < topLevelParentMap.next; i++) + for (int i = 0; i < topLevelParentMap.next; i++) { fprintf(stderr, "nxagentPrintRootlessTopLevelWindowMap: [%d] pWin at [%p] XID at [%ld].\n", i, (void *) topLevelParentMap.elt[i].pWin, (long int) topLevelParentMap.elt[i].xid); @@ -136,9 +134,7 @@ void nxagentPrintRootlessTopLevelWindowMap(void) void nxagentRootlessAddTopLevelWindow(WindowPtr pWin, Window w) { - int i; - - for (i = 0; i < topLevelParentMap.next; i++) + for (int i = 0; i < topLevelParentMap.next; i++) { if (topLevelParentMap.elt[i].pWin == pWin) { @@ -181,9 +177,7 @@ void nxagentRootlessAddTopLevelWindow(WindowPtr pWin, Window w) WindowPtr nxagentRootlessTopLevelWindow(Window w) { - int i; - - for (i = 0; i < topLevelParentMap.next; i++) + for (int i = 0; i < topLevelParentMap.next; i++) { if (w == topLevelParentMap.elt[i].xid) { @@ -196,9 +190,7 @@ WindowPtr nxagentRootlessTopLevelWindow(Window w) void nxagentRootlessDelTopLevelWindow(WindowPtr pWin) { - int i; - - for (i = 0; i < topLevelParentMap.next; i++) + for (int i = 0; i < topLevelParentMap.next; i++) { if (pWin == topLevelParentMap.elt[i].pWin) { @@ -506,7 +498,6 @@ int nxagentExportProperty(pWin, property, type, format, mode, nUnits, value) /* FIXME: is it okay here to ignore malloc fails? */ unsigned long *buffer = malloc(nUnits * sizeof(*buffer)); int *input = value; - int i; if (buffer) { @@ -514,7 +505,7 @@ int nxagentExportProperty(pWin, property, type, format, mode, nUnits, value) export = True; output = (char*) buffer; - for (i = 0; i < nUnits; i++) + for (int i = 0; i < nUnits; i++) { buffer[i] = input[i]; } @@ -644,7 +635,6 @@ int nxagentExportProperty(pWin, property, type, format, mode, nUnits, value) XlibAtom *atoms = malloc(nUnits * sizeof(*atoms)); Atom *input = value; const char *atomName = NULL; - int i; int j = 0; if (!atoms) @@ -659,7 +649,7 @@ int nxagentExportProperty(pWin, property, type, format, mode, nUnits, value) export = True; output = (char *) atoms; - for (i = 0; i < nUnits; i++) + for (int i = 0; i < nUnits; i++) { /* * Exporting the _NET_WM_PING property could @@ -703,7 +693,6 @@ int nxagentExportProperty(pWin, property, type, format, mode, nUnits, value) XlibWindow *wind = malloc(nUnits * sizeof(*wind)); ClientPtr pClient = wClient(pWin); WindowPtr pWindow; - int i; if (!wind) { @@ -717,7 +706,7 @@ int nxagentExportProperty(pWin, property, type, format, mode, nUnits, value) export = True; output = (char*) wind; - for (i = 0; i < nUnits; i++) + for (int i = 0; i < nUnits; i++) { pWindow = (WindowPtr)SecurityLookupWindow(input[i], pClient, DixDestroyAccess); @@ -774,15 +763,14 @@ int nxagentExportProperty(pWin, property, type, format, mode, nUnits, value) } else if (mode == PropModeReplace) { - int n; - char *data; + char * data = (char *) output; XDeleteProperty(nxagentDisplay, nxagentWindow(pWin), propertyX); - data = (char *) output; - while (nUnits > 0) { + int n; + if ((format >> 3) * nUnits + sizeof(xChangePropertyReq) < (MAX_REQUEST_SIZE << 2)) { @@ -1055,7 +1043,6 @@ void nxagentImportProperty(Window window, { Atom *atoms = malloc(nitems * sizeof(Atom)); Atom *input = (Atom*) buffer; - int i; if (atoms == NULL) { @@ -1070,7 +1057,7 @@ void nxagentImportProperty(Window window, import = True; output = (char *) atoms; - for (i = 0; i < nitems; i++) + for (int i = 0; i < nitems; i++) { atoms[i] = nxagentRemoteToLocalAtom(input[i]); @@ -1088,7 +1075,6 @@ void nxagentImportProperty(Window window, Window *input = (Window*) buffer; Window *wind = malloc(nitems * sizeof(Window)); WindowPtr pWindow; - int i; if (!wind) { @@ -1102,7 +1088,7 @@ void nxagentImportProperty(Window window, import = True; output = (char*) wind; - for (i = 0; i < nitems; i++) + for (int i = 0; i < nitems; i++) { pWindow = nxagentWindowPtr(input[i]); diff --git a/nx-X11/programs/Xserver/hw/nxagent/Screen.c b/nx-X11/programs/Xserver/hw/nxagent/Screen.c index b5d133b42..147a3108d 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Screen.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Screen.c @@ -2143,8 +2143,6 @@ Reply Total Cached Bits In Bits Out Bits/Reply Ratio Bool nxagentCloseScreen(ScreenPtr pScreen) { - int i; - #ifdef DEBUG fprintf(stderr, "running nxagentCloseScreen()\n"); #endif @@ -2157,7 +2155,7 @@ Bool nxagentCloseScreen(ScreenPtr pScreen) * them again. */ - for (i = 0; i < pScreen->numDepths; i++) + for (int i = 0; i < pScreen->numDepths; i++) { #ifdef DEBUG fprintf(stderr, "%s: freeing depth [%d] index [%d] vids [%p]\n", __func__, pScreen->allowedDepths[i].depth, i, (void*) pScreen->allowedDepths[i].vids); -- cgit v1.2.3 From 8205db4254b4dfba3ecc0cd800e334bdf430b3e3 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Wed, 19 Jun 2019 01:12:26 +0200 Subject: Font.c: code simplifications --- nx-X11/programs/Xserver/hw/nxagent/Font.c | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) (limited to 'nx-X11/programs/Xserver/hw') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Font.c b/nx-X11/programs/Xserver/hw/nxagent/Font.c index c135adb72..fb441d431 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Font.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Font.c @@ -369,18 +369,16 @@ static void nxagentFreeRemoteFontList(nxagentFontList *listRec) Bool nxagentFontFind(const char *name, int *pos) { - int low,high,res,iter,lpos; - if (!nxagentRemoteFontList.length) { *pos=0; return False; } - low = 0; - high = nxagentRemoteFontList.length - 1; - iter = 0; - res = 1; - lpos = nxagentRemoteFontList.length; + int low = 0; + int high = nxagentRemoteFontList.length - 1; + int iter = 0; + int res = 1; + int lpos = nxagentRemoteFontList.length; while (low <= high) { *pos = (high + low)/2; @@ -416,18 +414,15 @@ Bool nxagentFontFind(const char *name, int *pos) Bool nxagentFontLookUp(const char *name) { int i; - int result; - - char *scalable; if (name != NULL && strlen(name) == 0) { return 0; } - result = nxagentFontFind(name, &i); + int result = nxagentFontFind(name, &i); - scalable = NULL; + char *scalable = NULL; /* * Let's try with the scalable font description. @@ -435,9 +430,7 @@ Bool nxagentFontLookUp(const char *name) if (result == 0) { - scalable = nxagentMakeScalableFontName(name, 0); - - if (scalable != NULL) + if ((scalable = nxagentMakeScalableFontName(name, 0)) != NULL) { result = nxagentFontFind(scalable, &i); @@ -451,9 +444,7 @@ Bool nxagentFontLookUp(const char *name) if (result == 0) { - scalable = nxagentMakeScalableFontName(name, 1); - - if (scalable != NULL) + if ((scalable = nxagentMakeScalableFontName(name, 1)) != NULL) { result = nxagentFontFind(scalable, &i); @@ -888,7 +879,6 @@ static void nxagentFontDisconnect(FontPtr pFont, XID param1, void * param2) static void nxagentCollectFailedFont(FontPtr fpt, XID id) { - if (nxagentFailedToReconnectFonts.font == NULL) { nxagentFailedToReconnectFonts.size = 8; @@ -1632,7 +1622,6 @@ XFontStruct* nxagentLoadQueryFont(register Display *dpy, char *name, FontPtr pFo int nxagentFreeFont(XFontStruct *fs) { - if (fs -> per_char) { #ifdef USE_XF86BIGFONT -- cgit v1.2.3 From 234be0245324b01676aff764b756248f4e57b45d Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Wed, 19 Jun 2019 23:10:40 +0200 Subject: glyph.c: fix a read beyond end of heap buffer If compiled with -fsanitize=address this showed up when running startlxde: ==11551==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60d000018fbc at pc 0x7f270a9ed57b bp 0x7fff30ef3050 sp 0x7fff30ef2800 READ of size 204 at 0x60d000018fbc thread T0 #0 0x7f270a9ed57a (/usr/lib/x86_64-linux-gnu/libasan.so.5+0xb857a) #1 0x559dafcd5c93 in FindGlyphRef ../../render/glyph.c:179 #2 0x559dafcd705d in AddGlyph /work/nx-libs/nx-X11/programs/Xserver/hw/nxagent/NXglyph.c:71 #3 0x559dafccc0ff in ProcRenderAddGlyphs ../../mi/../render/render.c:1186 #4 0x559dafcbd5a5 in ProcRenderDispatch /work/nx-libs/nx-X11/programs/Xserver/hw/nxagent/NXrender.c:1689 #5 0x559dafcbc4ea in Dispatch /work/nx-libs/nx-X11/programs/Xserver/hw/nxagent/NXdispatch.c:476 #6 0x559dafc4e9b0 in main /work/nx-libs/nx-X11/programs/Xserver/dix/main.c:353 #7 0x7f2708e1d09a in __libc_start_main ../csu/libc-start.c:308 #8 0x559dafc4f5d9 in _start (/work/nx-libs/nx-X11/programs/Xserver/nxagent+0x6e5d9) 0x60d000018fbc is located 0 bytes to the right of 140-byte region [0x60d000018f30,0x60d000018fbc) allocated by thread T0 here: #0 0x7f270aa1e330 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.5+0xe9330) #1 0x559dafcd646c in AllocateGlyph ../../render/glyph.c:348 This happens when two glyphs are compared via memcmp and the smaller one happens to be identical to the beginning of the bigger one. Newer render implementations use a sha1 hash instead of memcmp so this patch will (hopefully) be obsolete once render gets updated. --- nx-X11/programs/Xserver/hw/nxagent/NXglyph.c | 61 ++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) (limited to 'nx-X11/programs/Xserver/hw') diff --git a/nx-X11/programs/Xserver/hw/nxagent/NXglyph.c b/nx-X11/programs/Xserver/hw/nxagent/NXglyph.c index 1f82e73dc..72d8242bd 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/NXglyph.c +++ b/nx-X11/programs/Xserver/hw/nxagent/NXglyph.c @@ -59,6 +59,67 @@ #endif +GlyphRefPtr +FindGlyphRef (GlyphHashPtr hash, CARD32 signature, Bool match, GlyphPtr compare) +{ + CARD32 elt, step, s; + GlyphPtr glyph; + GlyphRefPtr table, gr, del; + CARD32 tableSize = hash->hashSet->size; + + table = hash->table; + elt = signature % tableSize; + step = 0; + del = 0; + for (;;) + { + gr = &table[elt]; + s = gr->signature; + glyph = gr->glyph; + if (!glyph) + { + if (del) + gr = del; + break; + } + if (glyph == DeletedGlyph) + { + if (!del) + del = gr; + else if (gr == del) + break; + } +#ifdef NXAGENT_SERVER + else if (s == signature && match && glyph->size != compare->size) + { + /* + * if the glyphsize is different there's no need to do a memcmp + * because it will surely report difference. And even worse: + * it will read beyond the end of glyph under some + * circumstances, which can be detected when compiling with + * -fsanitize=address. + */ + } +#endif + else if (s == signature && + (!match || + memcmp (&compare->info, &glyph->info, compare->size) == 0)) + { + break; + } + if (!step) + { + step = signature % hash->hashSet->rehash; + if (!step) + step = 1; + } + elt += step; + if (elt >= tableSize) + elt -= tableSize; + } + return gr; +} + void AddGlyph (GlyphSetPtr glyphSet, GlyphPtr glyph, Glyph id) { -- cgit v1.2.3 From 6da1066109241d8c84cdb2b4674f4dd2a15c1a9c Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Wed, 19 Jun 2019 23:44:40 +0200 Subject: Keyboard.c: fix three memory leaks ==12976==ERROR: LeakSanitizer: detected memory leaks Direct leak of 6 byte(s) in 1 object(s) allocated from: #0 0x7f510b3ac810 in strdup (/usr/lib/x86_64-linux-gnu/libasan.so.5+0x3a810) #1 0x559ca29c5035 in nxagentKeyboardProc /home/uli/work/nx/ArcticaProject/nx-libs/nx-X11/programs/Xserver/hw/nxagent/Keyboard.c:866 #2 0x7a29bff07 () Direct leak of 1 byte(s) in 1 object(s) allocated from: #0 0x7f510b3ac810 in strdup (/usr/lib/x86_64-linux-gnu/libasan.so.5+0x3a810) #1 0x559ca29c509a in nxagentKeyboardProc /home/uli/work/nx/ArcticaProject/nx-libs/nx-X11/programs/Xserver/hw/nxagent/Keyboard.c:870 #2 0x7a29bff07 () Direct leak of 1 byte(s) in 1 object(s) allocated from: #0 0x7f510b3ac810 in strdup (/usr/lib/x86_64-linux-gnu/libasan.so.5+0x3a810) #1 0x559ca29c507f in nxagentKeyboardProc /home/uli/work/nx/ArcticaProject/nx-libs/nx-X11/programs/Xserver/hw/nxagent/Keyboard.c:869 #2 0x7a29bff07 () SUMMARY: AddressSanitizer: 8 byte(s) leaked in 3 allocation(s). --- nx-X11/programs/Xserver/hw/nxagent/Keyboard.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'nx-X11/programs/Xserver/hw') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Keyboard.c b/nx-X11/programs/Xserver/hw/nxagent/Keyboard.c index cff92ec48..b2ae7dfd1 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Keyboard.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Keyboard.c @@ -945,6 +945,10 @@ XkbError: { NXShadowInitKeymap(&(pDev->key->curKeySyms)); } + + free(rules); + free(variant); + free(options); } if (xkb) -- cgit v1.2.3 From 78eff73e4a8cf6a428dd4bd5ed50e0515ec8794f Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Thu, 20 Jun 2019 00:51:32 +0200 Subject: render: Propagate allocation failure from createSourcePicture() commit 211d4c2d353b5e379716484055a3f58235ea65f4 Author: Chris Wilson Date: Wed Dec 14 15:55:22 2011 +0000 render: Propagate allocation failure from createSourcePicture() All the callers were already checking for failure, except that createSourcePicture() itself was failing to check whether it successfully allocated the Picture. [ajax: Rebase, fix line wrap of preceding line] Signed-off-by: Chris Wilson Reviewed-by: Jeremy Huddleston --- nx-X11/programs/Xserver/hw/nxagent/NXpicture.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'nx-X11/programs/Xserver/hw') diff --git a/nx-X11/programs/Xserver/hw/nxagent/NXpicture.c b/nx-X11/programs/Xserver/hw/nxagent/NXpicture.c index e35d1e9bc..01821f474 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/NXpicture.c +++ b/nx-X11/programs/Xserver/hw/nxagent/NXpicture.c @@ -318,6 +318,8 @@ static PicturePtr createSourcePicture(void) sizeof(nxagentPrivPictureRec); pPicture = (PicturePtr) calloc(1, totalPictureSize); + if (!pPicture) + return 0; if (pPicture != NULL) { -- cgit v1.2.3 From e63d9de4565b97645956adf19d7f162ae0d471bd Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Thu, 20 Jun 2019 00:59:16 +0200 Subject: NXrender: fix another memleak --- nx-X11/programs/Xserver/hw/nxagent/NXrender.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'nx-X11/programs/Xserver/hw') diff --git a/nx-X11/programs/Xserver/hw/nxagent/NXrender.c b/nx-X11/programs/Xserver/hw/nxagent/NXrender.c index fd9c0be82..190f746a4 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/NXrender.c +++ b/nx-X11/programs/Xserver/hw/nxagent/NXrender.c @@ -1004,7 +1004,11 @@ ProcRenderCompositeGlyphs (ClientPtr client) elementsBase = malloc(nlist * sizeof(XGlyphElt8)); if (!elementsBase) - return BadAlloc; + { + free(glyphsBase); + free(listsBase); + return BadAlloc; + } buffer = (CARD8 *) (stuff + 1); glyphs = glyphsBase; -- cgit v1.2.3 From 213e63eed7f808633dc865af94a9ea4ee703f228 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Thu, 20 Jun 2019 01:21:44 +0200 Subject: Screen.c: fix two memleaks While at it create and use the freeDepths() helper function. --- nx-X11/programs/Xserver/hw/nxagent/Screen.c | 37 ++++++++++++++--------------- 1 file changed, 18 insertions(+), 19 deletions(-) (limited to 'nx-X11/programs/Xserver/hw') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Screen.c b/nx-X11/programs/Xserver/hw/nxagent/Screen.c index 147a3108d..67151733f 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Screen.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Screen.c @@ -844,6 +844,19 @@ static int nxagentColorOffset(unsigned long mask) return count; } +void freeDepths(DepthPtr depths, int num) +{ + for (int i = 0; i < num; i++) + { + #ifdef DEBUG + fprintf(stderr, "%s: freeing depth [%d] index [%d] vids [%p]\n", __func__, depths[i].depth, i, (void*) depths[i].vids); + #endif + free(depths[i].vids); + depths[i].vids = NULL; + } + free(depths); +} + Bool nxagentOpenScreen(ScreenPtr pScreen, int argc, char *argv[]) { @@ -1335,6 +1348,7 @@ Bool nxagentOpenScreen(ScreenPtr pScreen, if (!pFrameBufferBits) { + freeDepths(depths, numDepths); return FALSE; } @@ -1356,6 +1370,7 @@ Bool nxagentOpenScreen(ScreenPtr pScreen, if (!fbScreenInit(pScreen, pFrameBufferBits, nxagentOption(RootWidth), nxagentOption(RootHeight), monitorResolution, monitorResolution, PixmapBytePad(nxagentOption(RootWidth), rootDepth), bitsPerPixel)) { + freeDepths(depths, numDepths); return FALSE; } @@ -1391,15 +1406,7 @@ Bool nxagentOpenScreen(ScreenPtr pScreen, * by fbScreenInit with our own. */ - for (int i = 0; i < pScreen->numDepths; i++) - { - #ifdef DEBUG - fprintf(stderr, "%s: freeing depth [%d] index [%d] vids [%p]\n", __func__, pScreen->allowedDepths[i].depth, i, (void*) pScreen->allowedDepths[i].vids); - #endif - free(pScreen->allowedDepths[i].vids); - } - - free(pScreen -> allowedDepths); + freeDepths(pScreen->allowedDepths, pScreen->numDepths); pScreen -> allowedDepths = depths; pScreen -> numDepths = numDepths; pScreen -> rootDepth = rootDepth; @@ -2155,15 +2162,8 @@ Bool nxagentCloseScreen(ScreenPtr pScreen) * them again. */ - for (int i = 0; i < pScreen->numDepths; i++) - { - #ifdef DEBUG - fprintf(stderr, "%s: freeing depth [%d] index [%d] vids [%p]\n", __func__, pScreen->allowedDepths[i].depth, i, (void*) pScreen->allowedDepths[i].vids); - #endif - free(pScreen->allowedDepths[i].vids); - pScreen->allowedDepths[i].vids = NULL; - } - + freeDepths(pScreen->allowedDepths, pScreen->numDepths); + pScreen->allowedDepths = NULL; pScreen->numDepths = 0; /* @@ -2172,7 +2172,6 @@ Bool nxagentCloseScreen(ScreenPtr pScreen) free(((PixmapPtr)pScreen -> devPrivate) -> devPrivate.ptr); free(pScreen->devPrivate);pScreen->devPrivate = NULL; - free(pScreen->allowedDepths); pScreen->allowedDepths = NULL; free(pScreen->visuals); pScreen->visuals = NULL; fbCloseScreen(pScreen); -- cgit v1.2.3 From bb08043a65ba7e600fafaa3c703915fcb8ad79d4 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Thu, 20 Jun 2019 01:29:21 +0200 Subject: Screen.c: fix two more memleaks of visuals --- nx-X11/programs/Xserver/hw/nxagent/Screen.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'nx-X11/programs/Xserver/hw') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Screen.c b/nx-X11/programs/Xserver/hw/nxagent/Screen.c index 67151733f..6ec4b245f 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Screen.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Screen.c @@ -1349,6 +1349,7 @@ Bool nxagentOpenScreen(ScreenPtr pScreen, if (!pFrameBufferBits) { freeDepths(depths, numDepths); + free(visuals); return FALSE; } @@ -1371,6 +1372,7 @@ Bool nxagentOpenScreen(ScreenPtr pScreen, monitorResolution, monitorResolution, PixmapBytePad(nxagentOption(RootWidth), rootDepth), bitsPerPixel)) { freeDepths(depths, numDepths); + free(visuals); return FALSE; } -- cgit v1.2.3 From 528e1e4ef520506733ac3eeef374fcca41214cd1 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Thu, 20 Jun 2019 01:31:17 +0200 Subject: NXpicture.c: code simplification --- nx-X11/programs/Xserver/hw/nxagent/NXpicture.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'nx-X11/programs/Xserver/hw') diff --git a/nx-X11/programs/Xserver/hw/nxagent/NXpicture.c b/nx-X11/programs/Xserver/hw/nxagent/NXpicture.c index 01821f474..491af5b30 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/NXpicture.c +++ b/nx-X11/programs/Xserver/hw/nxagent/NXpicture.c @@ -303,21 +303,17 @@ CreateSolidPicture (Picture pid, xRenderColor *color, int *error) static PicturePtr createSourcePicture(void) { - PicturePtr pPicture; - extern int nxagentPicturePrivateIndex; - unsigned int totalPictureSize; - /* * Compute size of entire PictureRect, plus privates. */ - totalPictureSize = sizeof(PictureRec) + + unsigned int totalPictureSize = sizeof(PictureRec) + picturePrivateCount * sizeof(DevUnion) + sizeof(nxagentPrivPictureRec); - pPicture = (PicturePtr) calloc(1, totalPictureSize); + PicturePtr pPicture = (PicturePtr) calloc(1, totalPictureSize); if (!pPicture) return 0; -- cgit v1.2.3 From fd7e1f989b757667e7d7a3f0d08c9ee4b21a3a7c Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Thu, 20 Jun 2019 18:52:31 +0200 Subject: Keyboard.c: rearrange code to make cppcheck happy Otherwise it will (falsely) report "Memory pointed to by 'sessionpath' is freed twice." --- nx-X11/programs/Xserver/hw/nxagent/Keyboard.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'nx-X11/programs/Xserver/hw') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Keyboard.c b/nx-X11/programs/Xserver/hw/nxagent/Keyboard.c index b2ae7dfd1..7330784de 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Keyboard.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Keyboard.c @@ -1696,7 +1696,10 @@ static char* getKeyboardFilePath(void) free(sessionpath); FatalError("malloc for keyboard file path failed."); } - free(sessionpath); + else + { + free(sessionpath); + } } else { -- cgit v1.2.3 From b4d3dc5bff6a8d3b09a61dbf8421a46fd23b82e8 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Thu, 20 Jun 2019 19:14:10 +0200 Subject: NXdixfonts.c: fix index out of bounds --- nx-X11/programs/Xserver/hw/nxagent/NXdixfonts.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'nx-X11/programs/Xserver/hw') diff --git a/nx-X11/programs/Xserver/hw/nxagent/NXdixfonts.c b/nx-X11/programs/Xserver/hw/nxagent/NXdixfonts.c index 50bf719c6..bfb208593 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/NXdixfonts.c +++ b/nx-X11/programs/Xserver/hw/nxagent/NXdixfonts.c @@ -1216,7 +1216,7 @@ nxdoListFontsAndAliases(client, fss) if (c->savedName) { memcpy(tmp,c->savedName,c->savedNameLen>255?255:c->savedNameLen); - tmp[c->savedNameLen>255?256:c->savedNameLen]=0; + tmp[c->savedNameLen>255?255:c->savedNameLen]=0; if (nxagentFontLookUp(tmp)) break; else tmp[0]=0; @@ -1225,7 +1225,7 @@ nxdoListFontsAndAliases(client, fss) else { memcpy(tmp,name,namelen>255?255:namelen); - tmp[namelen>255?256:namelen]=0; + tmp[namelen>255?255:namelen]=0; if (nxagentFontLookUp(tmp)) break; else tmp[0]=0; -- cgit v1.2.3 From d48824195009b2497b4233c9d3f2a8f9c1e6a2d7 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Thu, 20 Jun 2019 19:51:00 +0200 Subject: compext/Png.c: late image_index allocation Move allocation of image_index close before first_use. This way we do not need to free it if previous step fail. And we cannot forget that free() call. While at it replace malloc+memset by calloc. --- nx-X11/programs/Xserver/hw/nxagent/compext/Png.c | 35 ++++++++++++------------ 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'nx-X11/programs/Xserver/hw') diff --git a/nx-X11/programs/Xserver/hw/nxagent/compext/Png.c b/nx-X11/programs/Xserver/hw/nxagent/compext/Png.c index 0a258c5a3..e80f3879d 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/compext/Png.c +++ b/nx-X11/programs/Xserver/hw/nxagent/compext/Png.c @@ -253,17 +253,6 @@ char *PngCompressData(XImage *image, int *compressed_size) NXColorTable color_table[NB_COLOR_MAX]; CARD8 *image_index; - image_index = (CARD8 *) malloc((image -> height) * (image -> width) * sizeof(CARD8)); - - /* - * TODO: Be sure the padded bytes are cleaned. - * It would be better to set to zero the bytes - * that are not aligned to the word boundary - * at the end of the procedure. - */ - - memset(image_index, 0, (image -> height) * (image -> width) * sizeof(CARD8)); - *compressed_size = 0; pngDataLen = 0; @@ -283,7 +272,6 @@ char *PngCompressData(XImage *image, int *compressed_size) bitsPerPixel); #endif - free(image_index); return NULL; } @@ -316,7 +304,6 @@ char *PngCompressData(XImage *image, int *compressed_size) fprintf(stderr, "******PngCompressData: PANIC! Failed creating the png_create_write_struct.\n"); #endif - free(image_index); return NULL; } @@ -329,7 +316,6 @@ char *PngCompressData(XImage *image, int *compressed_size) #endif png_destroy_write_struct(&png_ptr, NULL); - free(image_index); return NULL; } @@ -341,7 +327,6 @@ char *PngCompressData(XImage *image, int *compressed_size) #endif png_destroy_write_struct(&png_ptr, &info_ptr); - free(image_index); return NULL; } @@ -364,8 +349,6 @@ char *PngCompressData(XImage *image, int *compressed_size) PNG_DEST_SIZE(w, h)); #endif - free(image_index); - return NULL; } @@ -383,6 +366,24 @@ char *PngCompressData(XImage *image, int *compressed_size) return NULL; } + image_index = (CARD8 *) calloc(1, (image -> height) * (image -> width) * sizeof(CARD8)); + if (image_index == NULL) + { + #ifdef PANIC + fprintf(stderr, "******PngCompressData: PANIC! Could not alloc image_index.\n"); + #endif + + free(pngCompBuf); + return NULL; + } + + /* + * TODO: Be sure the padded bytes are cleaned. + * It would be better to set to zero the bytes + * that are not aligned to the word boundary + * at the end of the procedure. + */ + png_set_compression_level(png_ptr, PNG_Z_LEVEL); if (bitsPerPixel == 16) -- cgit v1.2.3 From e440e722d8639411722d8a2499df46fe18c45f31 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Thu, 20 Jun 2019 19:53:39 +0200 Subject: compext/Png.c: simplify srcBuf allocation --- nx-X11/programs/Xserver/hw/nxagent/compext/Png.c | 43 +++++++----------------- 1 file changed, 13 insertions(+), 30 deletions(-) (limited to 'nx-X11/programs/Xserver/hw') diff --git a/nx-X11/programs/Xserver/hw/nxagent/compext/Png.c b/nx-X11/programs/Xserver/hw/nxagent/compext/Png.c index e80f3879d..77a1941ea 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/compext/Png.c +++ b/nx-X11/programs/Xserver/hw/nxagent/compext/Png.c @@ -481,47 +481,23 @@ char *PngCompressData(XImage *image, int *compressed_size) return NULL; } + int count; if (color_type == PNG_COLOR_TYPE_PALETTE) { - srcBuf = (CARD8 *) malloc(w * sizeof(CARD8)); - - if (srcBuf == NULL) - { - #ifdef PANIC - fprintf(stderr, "******PngCompressData: PANIC! Cannot allocate [%d] bytes.\n", - (int) (w * sizeof(CARD8))); - #endif - - free(image_index); - - return NULL; - } - - /* - * TODO: Be sure the padded bytes are cleaned. - * It would be better to set to zero the bytes - * that are not aligned to the word boundary - * at the end of the procedure. - */ - - memset(srcBuf, 0, w * sizeof(CARD8)); + count = w; } else { - srcBuf = (CARD8 *) malloc(w * 3 * sizeof(CARD8)); - - /* - * TODO: See above. - */ - - memset(srcBuf, 0, w * 3 * sizeof(CARD8)); + count = 3 * w; } + srcBuf = (CARD8 *) calloc(count, sizeof(CARD8)); + if (srcBuf == NULL) { #ifdef PANIC fprintf(stderr, "******PngCompressData: PANIC! Cannot allocate [%d] bytes.\n", - w * 3); + (int) (count * sizeof(CARD8))); #endif free(pngCompBuf); @@ -530,6 +506,13 @@ char *PngCompressData(XImage *image, int *compressed_size) return NULL; } + /* + * TODO: Be sure the padded bytes are cleaned. + * It would be better to set to zero the bytes + * that are not aligned to the word boundary + * at the end of the procedure. + */ + for (dy = 0; dy < h; dy++) { if (color_type == PNG_COLOR_TYPE_RGB) -- cgit v1.2.3 From 956caeb8af1f14a52879d39c98caeb1e13edd546 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Thu, 20 Jun 2019 19:54:44 +0200 Subject: compext/Png.c: Nullify after free --- nx-X11/programs/Xserver/hw/nxagent/compext/Png.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'nx-X11/programs/Xserver/hw') diff --git a/nx-X11/programs/Xserver/hw/nxagent/compext/Png.c b/nx-X11/programs/Xserver/hw/nxagent/compext/Png.c index 77a1941ea..5c3a27612 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/compext/Png.c +++ b/nx-X11/programs/Xserver/hw/nxagent/compext/Png.c @@ -532,8 +532,8 @@ char *PngCompressData(XImage *image, int *compressed_size) dy, h); #endif - free(srcBuf); - free(image_index); + free(srcBuf); srcBuf = NULL; + free(image_index); image_index = NULL; if (setjmp(png_jmpbuf(png_ptr))) { -- cgit v1.2.3 From 2bb498a4c767b7d12db84e59b77020bcd70a057c Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Fri, 21 Jun 2019 11:38:39 +0200 Subject: Keyboard.c: fix another cppcheck finding [Keyboard.c:559]: (error) Shifting signed 32-bit value by 31 bits is undefined behaviour --- nx-X11/programs/Xserver/hw/nxagent/Keyboard.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'nx-X11/programs/Xserver/hw') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Keyboard.c b/nx-X11/programs/Xserver/hw/nxagent/Keyboard.c index 7330784de..8ff4528a1 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Keyboard.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Keyboard.c @@ -555,8 +555,9 @@ void nxagentChangeKeyboardControl(DeviceIntPtr pDev, KeybdCtrl *ctrl) for (int i = 1; i <= 32; i++) { + unsigned int mask = (unsigned int)1 << (i - 1); values.led = i; - values.led_mode = (ctrl->leds & (1 << (i - 1))) ? LedModeOn : LedModeOff; + values.led_mode = (ctrl->leds & mask) ? LedModeOn : LedModeOff; XChangeKeyboardControl(nxagentDisplay, value_mask, &values); } -- cgit v1.2.3 From 364035c00258c17924174dac7921b5a8e68e6459 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Fri, 21 Jun 2019 11:39:03 +0200 Subject: Keyboard.c: use existing define instead of hardcoced value --- nx-X11/programs/Xserver/hw/nxagent/Keyboard.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nx-X11/programs/Xserver/hw') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Keyboard.c b/nx-X11/programs/Xserver/hw/nxagent/Keyboard.c index 8ff4528a1..4952c0197 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Keyboard.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Keyboard.c @@ -553,7 +553,7 @@ void nxagentChangeKeyboardControl(DeviceIntPtr pDev, KeybdCtrl *ctrl) value_mask = KBLed | KBLedMode; - for (int i = 1; i <= 32; i++) + for (int i = 1; i <= XkbNumIndicators; i++) { unsigned int mask = (unsigned int)1 << (i - 1); values.led = i; -- cgit v1.2.3