Unverified Commit 8c3bb271 authored by Mike Gabriel's avatar Mike Gabriel

Merge branch 'uli42-pr/pvs_findings' into 3.6.x

parents b6669955 1b80750f
...@@ -385,12 +385,16 @@ static void nxagentExpandCache(void) ...@@ -385,12 +385,16 @@ static void nxagentExpandCache(void)
{ {
privAtomMapSize += NXAGENT_ATOM_MAP_SIZE_INCREMENT; privAtomMapSize += NXAGENT_ATOM_MAP_SIZE_INCREMENT;
privAtomMap = realloc(privAtomMap, privAtomMapSize * sizeof(AtomMap)); AtomMap * newmap = realloc(privAtomMap, privAtomMapSize * sizeof(AtomMap));
if (privAtomMap == NULL) if (newmap == NULL)
{ {
FatalError("nxagentExpandCache: realloc failed\n"); FatalError("nxagentExpandCache: realloc failed\n");
} }
else
{
privAtomMap = newmap;
}
} }
/* /*
...@@ -405,19 +409,23 @@ static void nxagentWriteAtom(Atom local, XlibAtom remote, const char *string) ...@@ -405,19 +409,23 @@ static void nxagentWriteAtom(Atom local, XlibAtom remote, const char *string)
#ifdef WARNING #ifdef WARNING
if (s == NULL) if (s == NULL)
{ {
fprintf(stderr, "nxagentWriteAtom: Malloc failed.\n"); /* we only warn here, because s being NULL ist not problem, it
will only result in NULL being stored in the privAtomMap, which
is perfectly legal. */
fprintf(stderr, "%s: Malloc failed.\n", __func__);
} }
#endif #endif
if (privLastAtom == privAtomMapSize) if (privLastAtom == privAtomMapSize)
{ {
/* will issue a fatal error, therefore no further check here */
nxagentExpandCache(); nxagentExpandCache();
} }
privAtomMap[privLastAtom].local = local; privAtomMap[privLastAtom].local = local;
privAtomMap[privLastAtom].remote = remote; privAtomMap[privLastAtom].remote = remote;
privAtomMap[privLastAtom].string = s; privAtomMap[privLastAtom].string = s;
privAtomMap[privLastAtom].length = strlen(s); privAtomMap[privLastAtom].length = s ? strlen(s) : 0;
privLastAtom++; privLastAtom++;
} }
......
...@@ -482,7 +482,7 @@ void nxagentResolveColor(unsigned short *pRed, unsigned short *pGreen, ...@@ -482,7 +482,7 @@ void nxagentResolveColor(unsigned short *pRed, unsigned short *pGreen,
unsigned int limg = pVisual->ColormapEntries - 1; unsigned int limg = pVisual->ColormapEntries - 1;
/* rescale to gray then [0..limg] then [0..65535] then rgb bits */ /* rescale to gray then [0..limg] then [0..65535] then rgb bits */
*pRed = (30L * *pRed + 59L * *pGreen + 11L * *pBlue) / 100; *pRed = (30L * *pRed + 59L * *pGreen + 11L * *pBlue) / 100;
*pRed = ((((*pRed * (limg + 1))) >> 16) * 65535) / limg; *pRed = (((*pRed * (limg + 1)) >> 16) * 65535) / limg;
*pBlue = *pGreen = *pRed = ((*pRed >> shift) * 65535) / lim; *pBlue = *pGreen = *pRed = ((*pRed >> shift) * 65535) / lim;
} }
else else
...@@ -573,7 +573,7 @@ Bool nxagentReconnectAllColormap(void *p0) ...@@ -573,7 +573,7 @@ Bool nxagentReconnectAllColormap(void *p0)
for (int cid = 0; (cid < MAXCLIENTS) && success; cid++) for (int cid = 0; (cid < MAXCLIENTS) && success; cid++)
{ {
if (clients[cid] && success) if (clients[cid])
{ {
FindClientResourcesByType(clients[cid], RT_COLORMAP, nxagentReconnectColormap, &success); FindClientResourcesByType(clients[cid], RT_COLORMAP, nxagentReconnectColormap, &success);
} }
......
...@@ -2576,13 +2576,19 @@ Bool nxagentReconnectDisplay(void *p0) ...@@ -2576,13 +2576,19 @@ Bool nxagentReconnectDisplay(void *p0)
nxagentNumDefaultColormaps = nxagentNumVisuals; nxagentNumDefaultColormaps = nxagentNumVisuals;
nxagentDefaultColormaps = (Colormap *) realloc(nxagentDefaultColormaps, {
Colormap * tmp = (Colormap *) realloc(nxagentDefaultColormaps,
nxagentNumDefaultColormaps * sizeof(Colormap)); nxagentNumDefaultColormaps * sizeof(Colormap));
if (tmp == NULL)
if (nxagentDefaultColormaps == NULL)
{ {
SAFE_free(nxagentDefaultColormaps);
FatalError("Can't allocate memory for the default colormaps\n"); FatalError("Can't allocate memory for the default colormaps\n");
} }
else
{
nxagentDefaultColormaps = tmp;
}
}
reconnectDisplayState = ALLOC_DEF_COLORMAP; reconnectDisplayState = ALLOC_DEF_COLORMAP;
......
...@@ -1605,9 +1605,11 @@ void nxagentUnmarkCorruptedRegion(DrawablePtr pDrawable, RegionPtr pRegion) ...@@ -1605,9 +1605,11 @@ void nxagentUnmarkCorruptedRegion(DrawablePtr pDrawable, RegionPtr pRegion)
* If the drawable becomes synchronized, the counter reporting the * If the drawable becomes synchronized, the counter reporting the
* number of corrupted drawables must be decreased. Moreover the * number of corrupted drawables must be decreased. Moreover the
* corrupted timestamp must be reset. * corrupted timestamp must be reset.
* Note: oldstatus has been checked above and is always
* "NotSynchronized" here.
*/ */
if (oldStatus == NotSynchronized && if (/*oldStatus == NotSynchronized &&*/
nxagentDrawableStatus(pDrawable) == Synchronized) nxagentDrawableStatus(pDrawable) == Synchronized)
{ {
if (pDrawable -> type == DRAWABLE_PIXMAP) if (pDrawable -> type == DRAWABLE_PIXMAP)
......
...@@ -435,6 +435,11 @@ N/A ...@@ -435,6 +435,11 @@ N/A
int len = (max_keycode - min_keycode + 1) * mapWidth; int len = (max_keycode - min_keycode + 1) * mapWidth;
keymap = (KeySym *)malloc(len * sizeof(KeySym)); keymap = (KeySym *)malloc(len * sizeof(KeySym));
if (keymap == NULL)
{
XFreeModifiermap(modifier_keymap);
return -1;
}
for(int i = 0; i < len; ++i) for(int i = 0; i < len; ++i)
{ {
keymap[i] = keymap64[i]; keymap[i] = keymap64[i];
...@@ -1425,12 +1430,10 @@ static void nxagentXkbGetRemoteNames(void) ...@@ -1425,12 +1430,10 @@ static void nxagentXkbGetRemoteNames(void)
if ((after > 0) || (type != XA_STRING) || (format != 8)) if ((after > 0) || (type != XA_STRING) || (format != 8))
{ {
if (data) /* data non-null - has been checked above */
{
SAFE_XFree(data); SAFE_XFree(data);
return; return;
} }
}
char *name = data; char *name = data;
......
...@@ -296,6 +296,13 @@ miGlyphs (CARD8 op, ...@@ -296,6 +296,13 @@ miGlyphs (CARD8 op,
else else
{ {
nxagentGlyphsExtents = (BoxPtr) malloc(sizeof(BoxRec)); nxagentGlyphsExtents = (BoxPtr) malloc(sizeof(BoxRec));
if (!nxagentGlyphsExtents)
{
#ifdef WARNING
fprintf(stderr, "WARNING! Cannot allocate GlyphExtents\n");
#endif
return;
}
GlyphExtents (nlist, list, glyphs, &extents); GlyphExtents (nlist, list, glyphs, &extents);
......
...@@ -320,8 +320,6 @@ static PicturePtr createSourcePicture(void) ...@@ -320,8 +320,6 @@ static PicturePtr createSourcePicture(void)
if (!pPicture) if (!pPicture)
return 0; return 0;
if (pPicture != NULL)
{
DevUnion *ppriv = (DevUnion *) (pPicture + 1); DevUnion *ppriv = (DevUnion *) (pPicture + 1);
for (int i = 0; i < picturePrivateCount; ++i) for (int i = 0; i < picturePrivateCount; ++i)
...@@ -340,7 +338,6 @@ static PicturePtr createSourcePicture(void) ...@@ -340,7 +338,6 @@ static PicturePtr createSourcePicture(void)
pPicture -> devPrivates = ppriv; pPicture -> devPrivates = ppriv;
nxagentPicturePriv(pPicture) -> picture = 0; nxagentPicturePriv(pPicture) -> picture = 0;
}
pPicture->pDrawable = 0; pPicture->pDrawable = 0;
pPicture->pFormat = 0; pPicture->pFormat = 0;
......
...@@ -788,12 +788,16 @@ void nxagentSetReconnectError(int id, char *format, ...) ...@@ -788,12 +788,16 @@ void nxagentSetReconnectError(int id, char *format, ...)
size = (size ? size * 2 : NXAGENT_RECONNECT_DEFAULT_MESSAGE_SIZE); size = (size ? size * 2 : NXAGENT_RECONNECT_DEFAULT_MESSAGE_SIZE);
} }
nxagentReconnectErrorMessage = realloc(nxagentReconnectErrorMessage, size); char *tmp = realloc(nxagentReconnectErrorMessage, size);
if (nxagentReconnectErrorMessage == NULL) if (tmp == NULL)
{ {
FatalError("realloc failed"); FatalError("realloc failed");
} }
else
{
nxagentReconnectErrorMessage = tmp;
}
} }
return; return;
......
...@@ -1248,7 +1248,7 @@ void nxagentGlyphs(CARD8 op, PicturePtr pSrc, PicturePtr pDst, ...@@ -1248,7 +1248,7 @@ void nxagentGlyphs(CARD8 op, PicturePtr pSrc, PicturePtr pDst,
PictFormatPtr maskFormat, INT16 xSrc, INT16 ySrc, int nlists, PictFormatPtr maskFormat, INT16 xSrc, INT16 ySrc, int nlists,
XGlyphElt8 *elts, int sizeID, GlyphPtr *glyphsBase) XGlyphElt8 *elts, int sizeID, GlyphPtr *glyphsBase)
{ {
BoxRec glyphBox; BoxRec glyphBox = {0};
XGlyphElt8 *elements; XGlyphElt8 *elements;
......
...@@ -502,7 +502,8 @@ int nxagentExportProperty(WindowPtr pWin, ...@@ -502,7 +502,8 @@ int nxagentExportProperty(WindowPtr pWin,
nxagentPropWMHints propHints = { nxagentPropWMHints propHints = {
.flags = wmHints.flags, .flags = wmHints.flags,
.input = (wmHints.input == True ? 1 : 0), /*.input = (wmHints.input == True ? 1 : 0), is always True*/
.input = 1,
.initialState = wmHints.initial_state, .initialState = wmHints.initial_state,
.iconPixmap = wmHints.icon_pixmap, .iconPixmap = wmHints.icon_pixmap,
.iconWindow = wmHints.icon_window, .iconWindow = wmHints.icon_window,
......
...@@ -1156,6 +1156,14 @@ Bool nxagentOpenScreen(ScreenPtr pScreen, int argc, char *argv[]) ...@@ -1156,6 +1156,14 @@ Bool nxagentOpenScreen(ScreenPtr pScreen, int argc, char *argv[])
*/ */
DepthPtr depths = (DepthPtr) malloc(nxagentNumDepths * sizeof(DepthRec)); DepthPtr depths = (DepthPtr) malloc(nxagentNumDepths * sizeof(DepthRec));
if (!depths)
{
#ifdef WARNING
fprintf(stderr, "WARNING: Could not allocate depths array\n");
#endif
/* FIXME: free data allocated above */
return False;
}
for (int i = 0; i < nxagentNumDepths; i++) for (int i = 0; i < nxagentNumDepths; i++)
{ {
...@@ -1177,6 +1185,14 @@ Bool nxagentOpenScreen(ScreenPtr pScreen, int argc, char *argv[]) ...@@ -1177,6 +1185,14 @@ Bool nxagentOpenScreen(ScreenPtr pScreen, int argc, char *argv[])
int numDepths = nxagentNumDepths; int numDepths = nxagentNumDepths;
VisualPtr visuals = (VisualPtr) malloc(nxagentNumVisuals * sizeof(VisualRec)); VisualPtr visuals = (VisualPtr) malloc(nxagentNumVisuals * sizeof(VisualRec));
if (!visuals)
{
#ifdef WARNING
fprintf(stderr, "WARNING: Could not allocate visual array\n");
#endif
/* FIXME: free data allocated above */
return False;
}
int defaultVisualIndex = 0; int defaultVisualIndex = 0;
...@@ -3058,6 +3074,14 @@ void nxagentShadowAdaptDepth(unsigned int width, unsigned int height, ...@@ -3058,6 +3074,14 @@ void nxagentShadowAdaptDepth(unsigned int width, unsigned int height,
unsigned char *cBuffer = malloc(length); unsigned char *cBuffer = malloc(length);
unsigned char *icBuffer = cBuffer; unsigned char *icBuffer = cBuffer;
if (!cBuffer)
{
#ifdef WARNING
fprintf(stderr, "WARNING: could not allocate cBuffer\n");
#endif
return;
}
Visual *pVisual = nxagentImageVisual((DrawablePtr) nxagentShadowPixmapPtr, nxagentShadowDepth); Visual *pVisual = nxagentImageVisual((DrawablePtr) nxagentShadowPixmapPtr, nxagentShadowDepth);
if (pVisual == NULL) if (pVisual == NULL)
...@@ -4203,6 +4227,13 @@ void nxagentSaveAreas(PixmapPtr pPixmap, RegionPtr prgnSave, int xorg, int yorg, ...@@ -4203,6 +4227,13 @@ void nxagentSaveAreas(PixmapPtr pPixmap, RegionPtr prgnSave, int xorg, int yorg,
int nRects = RegionNumRects(&cleanRegion); int nRects = RegionNumRects(&cleanRegion);
int size = nRects * sizeof(XRectangle); int size = nRects * sizeof(XRectangle);
XRectangle *pRects = (XRectangle *) malloc(size); XRectangle *pRects = (XRectangle *) malloc(size);
if (!pRects)
{
#ifdef WARNING
fprintf(stderr, "Could not allocate pRects\n");
#endif
return;
}
BoxPtr pBox = RegionRects(&cleanRegion); BoxPtr pBox = RegionRects(&cleanRegion);
for (int i = nRects; i-- > 0;) for (int i = nRects; i-- > 0;)
...@@ -4336,6 +4367,14 @@ void nxagentRestoreAreas(PixmapPtr pPixmap, RegionPtr prgnRestore, int xorg, ...@@ -4336,6 +4367,14 @@ void nxagentRestoreAreas(PixmapPtr pPixmap, RegionPtr prgnRestore, int xorg,
int nRects = RegionNumRects(clipRegion); int nRects = RegionNumRects(clipRegion);
int size = nRects * sizeof(XRectangle); int size = nRects * sizeof(XRectangle);
XRectangle *pRects = (XRectangle *) malloc(size); XRectangle *pRects = (XRectangle *) malloc(size);
if (!pRects)
{
#ifdef WARNING
fprintf(stderr, "Could not allocate pRects\n");
#endif
return;
}
BoxPtr pBox = RegionRects(clipRegion); BoxPtr pBox = RegionRects(clipRegion);
for (int i = nRects; i-- > 0;) for (int i = nRects; i-- > 0;)
......
...@@ -332,16 +332,11 @@ void nxagentRemoveSplashWindow(void) ...@@ -332,16 +332,11 @@ void nxagentRemoveSplashWindow(void)
fprintf(stderr, "%s: Destroying the splash window.\n", __func__); fprintf(stderr, "%s: Destroying the splash window.\n", __func__);
#endif #endif
if (!nxagentWMPassed)
{
#ifdef NXAGENT_ONSTART #ifdef NXAGENT_ONSTART
XSetSelectionOwner(nxagentDisplay, nxagentReadyAtom, XSetSelectionOwner(nxagentDisplay, nxagentReadyAtom,
nxagentDefaultWindows[0], CurrentTime); nxagentDefaultWindows[0], CurrentTime);
#endif #endif
nxagentWMPassed = True;
}
if (nxagentSplashWindow != None) if (nxagentSplashWindow != None)
{ {
XDestroyWindow(nxagentDisplay, nxagentSplashWindow); XDestroyWindow(nxagentDisplay, nxagentSplashWindow);
......
...@@ -3088,9 +3088,11 @@ static void nxagentReconnectWindow(void * param0, XID param1, void * data_buffer ...@@ -3088,9 +3088,11 @@ static void nxagentReconnectWindow(void * param0, XID param1, void * data_buffer
(void*)pWin, pWin -> drawable.id, nxagentWindow(pWin)); (void*)pWin, pWin -> drawable.id, nxagentWindow(pWin));
#endif #endif
/* FIXME: use XAllocSizeHints() */
#ifdef _XSERVER64 #ifdef _XSERVER64
data64 = (unsigned char *) malloc(sizeof(XSizeHints) + 4); data64 = (unsigned char *) malloc(sizeof(XSizeHints) + 4);
if (data64)
{
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
{ {
*(data64 + i) = *(data + i); *(data64 + i) = *(data + i);
...@@ -3113,6 +3115,13 @@ static void nxagentReconnectWindow(void * param0, XID param1, void * data_buffer ...@@ -3113,6 +3115,13 @@ static void nxagentReconnectWindow(void * param0, XID param1, void * data_buffer
else else
{ {
#ifdef WARNING #ifdef WARNING
fprintf(stderr, "%s: Failed to alloc memory for XSizeHints\n", __func__);
#endif
}
}
else
{
#ifdef WARNING
fprintf(stderr, "nxagentReconnectWindow: Failed to get property WM_NORMAL_HINTS on window %p\n", fprintf(stderr, "nxagentReconnectWindow: Failed to get property WM_NORMAL_HINTS on window %p\n",
(void*)pWin); (void*)pWin);
#endif #endif
...@@ -3657,6 +3666,14 @@ void nxagentAddStaticResizedWindow(WindowPtr pWin, unsigned long sequence, int o ...@@ -3657,6 +3666,14 @@ void nxagentAddStaticResizedWindow(WindowPtr pWin, unsigned long sequence, int o
StaticResizedWindowStruct *tmp = nxagentStaticResizedWindowList; StaticResizedWindowStruct *tmp = nxagentStaticResizedWindowList;
nxagentStaticResizedWindowList = malloc(sizeof(StaticResizedWindowStruct)); nxagentStaticResizedWindowList = malloc(sizeof(StaticResizedWindowStruct));
if (!nxagentStaticResizedWindowList)
{
#ifdef WARNING
fprintf(stderr, "WARNING: could not allocate memory for nxagentStaticResizedWindowList\n");
#endif
nxagentStaticResizedWindowList = tmp;
return;
}
nxagentStaticResizedWindowList -> next = tmp; nxagentStaticResizedWindowList -> next = tmp;
nxagentStaticResizedWindowList -> prev = NULL; nxagentStaticResizedWindowList -> prev = 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