From 8362f92cebbb2264d7fca7fdb84f82ecfea41932 Mon Sep 17 00:00:00 2001 From: Peter Howkins Date: Mon, 2 Apr 2018 18:08:40 +0100 Subject: [PATCH] dtwm: Resolve coverity warnings --- cde/programs/dtwm/Parse.c | 1 + cde/programs/dtwm/PopupMenu.c | 6 ++++-- cde/programs/dtwm/Session.c | 2 ++ cde/programs/dtwm/WmBackdrop.c | 10 ++-------- cde/programs/dtwm/WmCEvent.c | 2 +- cde/programs/dtwm/WmFP.c | 6 ++++-- cde/programs/dtwm/WmHelp.c | 10 +++++++++- cde/programs/dtwm/WmImage.c | 2 +- cde/programs/dtwm/WmMenu.c | 2 +- cde/programs/dtwm/WmMultiHead.c | 2 ++ cde/programs/dtwm/WmResParse.c | 5 ++++- cde/programs/dtwm/WmResource.c | 30 ++++++------------------------ cde/programs/dtwm/WmWinConf.c | 2 +- cde/programs/dtwm/WmWrkspace.c | 5 +---- 14 files changed, 39 insertions(+), 46 deletions(-) diff --git a/cde/programs/dtwm/Parse.c b/cde/programs/dtwm/Parse.c index 51011e32..262b842a 100644 --- a/cde/programs/dtwm/Parse.c +++ b/cde/programs/dtwm/Parse.c @@ -290,6 +290,7 @@ StringToAction (char * parse_source, { _DtSimpleError (panel.app_name, DtError, NULL, "Invalid Action -- %s", parse_source); + free (head_ptr); return (False); } diff --git a/cde/programs/dtwm/PopupMenu.c b/cde/programs/dtwm/PopupMenu.c index 81c5fca5..2a64463d 100644 --- a/cde/programs/dtwm/PopupMenu.c +++ b/cde/programs/dtwm/PopupMenu.c @@ -179,7 +179,7 @@ RenameWorkspaceCB (Widget w, { long rename_ws = (long) client_data; - SwitchData * switch_data; + SwitchData * switch_data = NULL; int i; @@ -195,7 +195,9 @@ RenameWorkspaceCB (Widget w, } } - SwitchRenameLabel (switch_data->buttons[rename_ws], panel.box_data[i]); + if(switch_data) { + SwitchRenameLabel (switch_data->buttons[rename_ws], panel.box_data[i]); + } } diff --git a/cde/programs/dtwm/Session.c b/cde/programs/dtwm/Session.c index 2d22f46f..9a5372ac 100644 --- a/cde/programs/dtwm/Session.c +++ b/cde/programs/dtwm/Session.c @@ -832,5 +832,7 @@ SessionDeleteAll(void) strcpy(srcname + srclen, entry->d_name); remove (srcname); } + + closedir(dir); } diff --git a/cde/programs/dtwm/WmBackdrop.c b/cde/programs/dtwm/WmBackdrop.c index ce455a81..02307426 100644 --- a/cde/programs/dtwm/WmBackdrop.c +++ b/cde/programs/dtwm/WmBackdrop.c @@ -440,14 +440,8 @@ ProcessBackdropResources( } pch = NULL; } - if (pchImageName) - { - free (pchImageName); /* temporary string */ - } - if (pchL) - { - free (pchL); /* temporary string */ - } + free (pchImageName); /* temporary string */ + free (pchL); /* temporary string */ } } } diff --git a/cde/programs/dtwm/WmCEvent.c b/cde/programs/dtwm/WmCEvent.c index 5afa336d..f87f29b6 100644 --- a/cde/programs/dtwm/WmCEvent.c +++ b/cde/programs/dtwm/WmCEvent.c @@ -1239,7 +1239,7 @@ void CheckButtonPressBuiltin (XButtonEvent *buttonEvent, Context context, Contex * the resources or the user has specifically requested * that "move" not be one of them. */ - if (pCD->clientFunctions & MWM_FUNC_MOVE) + if (pCD && (pCD->clientFunctions & MWM_FUNC_MOVE)) { wmGD.preMove = True; wmGD.preMoveX = buttonEvent->x_root; diff --git a/cde/programs/dtwm/WmFP.c b/cde/programs/dtwm/WmFP.c index 3e6a8286..5bd3690c 100644 --- a/cde/programs/dtwm/WmFP.c +++ b/cde/programs/dtwm/WmFP.c @@ -292,7 +292,7 @@ EmbeddedClientRegister (ControlData * control_data, if (embedded_client_list[i].wControl == control_data->icon) { Position remove_y; - Dimension adjust_y; + Dimension adjust_y = 0; /* This block will reparent the client window, move it */ @@ -312,7 +312,9 @@ EmbeddedClientRegister (ControlData * control_data, /* deleted control height plus 5 pixels of form offset */ - adjust_y = XtHeight (control_data->icon) + 5; + if(control_data->icon) { + adjust_y = XtHeight (control_data->icon) + 5; + } panel.embedded_client_count--; diff --git a/cde/programs/dtwm/WmHelp.c b/cde/programs/dtwm/WmHelp.c index e145db52..31e915e3 100644 --- a/cde/programs/dtwm/WmHelp.c +++ b/cde/programs/dtwm/WmHelp.c @@ -991,7 +991,9 @@ void WmDtHelpOnVersion ( Widget helpButton = NULL; Widget backButton = NULL; Widget closeButton = NULL; +#ifdef NO_MESSAGE_CATALOG XmString label = NULL; +#endif if((versionWidget != NULL) && (XtIsManaged(versionWidget))) @@ -1035,7 +1037,9 @@ void WmDtHelpOnVersion ( #endif XtSetValues(closeButton, setArgs2, n2); +#ifdef NO_MESSAGE_CATALOG if(label)XmStringFree(label); +#endif printButton = DtHelpQuickDialogGetChild( versionWidget, DtHELP_QUICK_PRINT_BUTTON ); @@ -1664,7 +1668,7 @@ RestoreHelpDialogs( int wsCnt; int cCount; int cachedCount=0; - char dialogName[10]; + char dialogName[18]; ClientData *pCD = NULL; char *tTitle = NULL; @@ -2787,7 +2791,9 @@ wmDtErrorDialog( if (pSD->dtHelp.errorDialog == NULL) { +#ifdef NO_MESSAGE_CATALOG XmString tmpXmString = (XmString)NULL; +#endif ac = 0; XtSetArg (al[ac], XmNmessageString, xmsMessage); ac++; @@ -2815,8 +2821,10 @@ wmDtErrorDialog( pSD->dtHelp.errorDialog = XmCreateErrorDialog (wParent, "Error Dialog", al, ac); +#ifdef NO_MESSAGE_CATALOG if (tmpXmString) XmStringFree(tmpXmString); +#endif wTemp = XmMessageBoxGetChild (pSD->dtHelp.errorDialog, XmDIALOG_HELP_BUTTON); diff --git a/cde/programs/dtwm/WmImage.c b/cde/programs/dtwm/WmImage.c index 29f72214..e05c2d3b 100644 --- a/cde/programs/dtwm/WmImage.c +++ b/cde/programs/dtwm/WmImage.c @@ -1081,7 +1081,7 @@ char *BitmapPathName (string) strncat (fileName, &wmGD.bitmapDirectory[1], MAXWMPATH - strlen (fileName)); } else { - strcpy (fileName, wmGD.bitmapDirectory); + snprintf(fileName, sizeof(fileName), "%s", wmGD.bitmapDirectory); } strncat (fileName, "/", MAXWMPATH - strlen (fileName)); strncat (fileName, string, MAXWMPATH - strlen (fileName)); diff --git a/cde/programs/dtwm/WmMenu.c b/cde/programs/dtwm/WmMenu.c index cb94caf4..e030aed5 100644 --- a/cde/programs/dtwm/WmMenu.c +++ b/cde/programs/dtwm/WmMenu.c @@ -4050,7 +4050,7 @@ void PostMenu (MenuSpec *menuSpec, ClientData *pCD, int x, int y, unsigned int b * Compute position if necessary (system menu). */ - if (!(flags & POST_AT_XY)) + if (pCD && !(flags & POST_AT_XY)) /* compute the position */ { GetSystemMenuPosition (pCD, &x, &y, menuSpec->height, newContext); diff --git a/cde/programs/dtwm/WmMultiHead.c b/cde/programs/dtwm/WmMultiHead.c index 4de6c6b9..dc3eb811 100644 --- a/cde/programs/dtwm/WmMultiHead.c +++ b/cde/programs/dtwm/WmMultiHead.c @@ -108,6 +108,8 @@ WmHeadInfo_t *GetHeadInfo(const ClientData *pcd) { return WmHI; } + free(WmHI); + /* No valid screen */ return NULL; } diff --git a/cde/programs/dtwm/WmResParse.c b/cde/programs/dtwm/WmResParse.c index cfdb6966..6202c489 100644 --- a/cde/programs/dtwm/WmResParse.c +++ b/cde/programs/dtwm/WmResParse.c @@ -2512,8 +2512,11 @@ FILE *FopenConfigFile (void) * Run the file through the C-preprocessor */ PreprocessConfigFile (); - if (pConfigStackTop->cppName) + if (pConfigStackTop && pConfigStackTop->cppName) { + if(fileP) { + fclose(fileP); + } /* open the result */ fileP = fopen (pConfigStackTop->cppName, "r"); } diff --git a/cde/programs/dtwm/WmResource.c b/cde/programs/dtwm/WmResource.c index 8a03160f..52255a3c 100644 --- a/cde/programs/dtwm/WmResource.c +++ b/cde/programs/dtwm/WmResource.c @@ -398,35 +398,17 @@ void InitBuiltinSystemMenu(void) else { /* put it together */ - strcpy(dsm, defaultSystemMenuName); - strcat(dsm, "\n{\n"); - strcat(dsm, ResString); - strcat(dsm, "\n"); - strcat(dsm, MovString); - strcat(dsm, "\n"); - strcat(dsm, SizString); - strcat(dsm, "\n"); - strcat(dsm, MinString); - strcat(dsm, "\n"); - strcat(dsm, MaxString); - strcat(dsm, "\n"); - strcat(dsm, LowString); - strcat(dsm, "\n"); - strcat(dsm, " no-label f.separator\n"); + snprintf(dsm, sizeof(dsm), "%s\n{\n%s)\n%s\n%s\n%s\n%s\n%s\n no-label f.separator\n", + defaultSystemMenuName, ResString, MovString, + SizString, MinString, MaxString, LowString); #ifdef WSM if (DtwmBehavior) { - strcat(dsm, OcpString); - strcat(dsm, "\n"); - strcat(dsm, OcaString); - strcat(dsm, "\n"); - strcat(dsm, RemString); - strcat(dsm, "\n"); - strcat(dsm, " no-label f.separator\n"); + snprintf(dsm, sizeof(dsm), "%s%s\n%s\n%s\n no-label f.separator\n", + dsm, OcpString, OcaString, RemString); } #endif /* WSM */ - strcat(dsm, CloString); - strcat(dsm, "\n}"); + snprintf(dsm, sizeof(dsm), "%s%s\n}", dsm, CloString); if ((builtinSystemMenu = (char *)XtMalloc ((unsigned int) (strlen(dsm) + 1))) == NULL) diff --git a/cde/programs/dtwm/WmWinConf.c b/cde/programs/dtwm/WmWinConf.c index 82107239..4e38f87a 100644 --- a/cde/programs/dtwm/WmWinConf.c +++ b/cde/programs/dtwm/WmWinConf.c @@ -4202,7 +4202,7 @@ StartMarqueeSelect(WmScreenData *pSD, XEvent *pev) /* * Set up static variables for succeeding events */ - if ((pev->type == ButtonPress) || (pev->type == ButtonRelease)) + if (pev && (pev->type == ButtonPress) || (pev->type == ButtonRelease)) { pointerX = pev->xbutton.x_root; pointerY = pev->xbutton.y_root; diff --git a/cde/programs/dtwm/WmWrkspace.c b/cde/programs/dtwm/WmWrkspace.c index 65e89343..6dcba7fe 100644 --- a/cde/programs/dtwm/WmWrkspace.c +++ b/cde/programs/dtwm/WmWrkspace.c @@ -3857,10 +3857,7 @@ SaveWorkspaceResources( XtFree(data); } - if (buffer) - { - XtFree(buffer); - } + XtFree(buffer); } /* END OF FUNCTION SaveWorkspaceResources */ -- 2.25.1