dtwm: Resolve coverity warnings
authorPeter Howkins <flibble@users.sf.net>
Mon, 2 Apr 2018 17:08:40 +0000 (18:08 +0100)
committerPeter Howkins <flibble@users.sf.net>
Mon, 2 Apr 2018 17:08:40 +0000 (18:08 +0100)
14 files changed:
cde/programs/dtwm/Parse.c
cde/programs/dtwm/PopupMenu.c
cde/programs/dtwm/Session.c
cde/programs/dtwm/WmBackdrop.c
cde/programs/dtwm/WmCEvent.c
cde/programs/dtwm/WmFP.c
cde/programs/dtwm/WmHelp.c
cde/programs/dtwm/WmImage.c
cde/programs/dtwm/WmMenu.c
cde/programs/dtwm/WmMultiHead.c
cde/programs/dtwm/WmResParse.c
cde/programs/dtwm/WmResource.c
cde/programs/dtwm/WmWinConf.c
cde/programs/dtwm/WmWrkspace.c

index 51011e322775317b5f187c37b1c83d5430120d21..262b842a1c3330e8d79f704935ccef1668756fde 100644 (file)
@@ -290,6 +290,7 @@ StringToAction (char * parse_source,
    {
       _DtSimpleError (panel.app_name, DtError, NULL, 
                      "Invalid Action -- %s", parse_source);
+      free (head_ptr);
       return (False);
    }
 
index 81c5fca576dcaca0b054e44b1c52fbc52ced092f..2a64463d02049ca43e643344a5d83d4d86858000 100644 (file)
@@ -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]);
+   }
 }
 
 
index 2d22f46f5c2ab8124593d2fd512857496174db19..9a5372ac97c958452e36dfd9bfdba18cbfdf63c8 100644 (file)
@@ -832,5 +832,7 @@ SessionDeleteAll(void)
       strcpy(srcname + srclen, entry->d_name);
       remove (srcname);
    }
+   
+   closedir(dir);
 }
 
index ce455a817732053ef5a15ad8a24d25cad5dc9877..023074266036b57fd54276179e54049abf01f6de 100644 (file)
@@ -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 */
        }
     }
 }
index 5afa336dae036df6421c973a872350d1c03a48d3..f87f29b6379cc6a8fcc167dccd8ddf0d7dcba28d 100644 (file)
@@ -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;
index 3e6a8286cf5fc4d6037087e22488552992f9a926..5bd3690c513c6bb469b2a8f25f92c0b009342cbd 100644 (file)
@@ -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--;
 
index e145db523d760b4bf427a620d1517dabae9b9a69..31e915e373ae6951810b8c7485e41f50fa402a26 100644 (file)
@@ -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);
index 29f722145d0463eaef46dbe024e9f33ecc293de7..e05c2d3bc297417c9cd1d01c0c8d00e9d8435889 100644 (file)
@@ -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));
index cb94caf428e6110e9a37e770e67ec99ac39c1596..e030aed5a8dcdbe20ad27c6a8a400bd0f99c6f0c 100644 (file)
@@ -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);
index 4de6c6b9726a523e0675ceb9d70a6865485b4bee..dc3eb811fac44db46eea981787c6d8389ad5307a 100644 (file)
@@ -108,6 +108,8 @@ WmHeadInfo_t *GetHeadInfo(const ClientData *pcd) {
             return WmHI;
     }
 
+    free(WmHI);
+
     /* No valid screen */
     return NULL;
 }
index cfdb6966b00121ec3f40127a45392990fce958a8..6202c4899e1067600280911ba0d8ecc14f96fb07 100644 (file)
@@ -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");
        }
index 8a03160f4455f9e22fc8f8d4b0885a6298f3fe5b..52255a3cb2b9600accf870c560d1060b66d79cce 100644 (file)
@@ -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)
index 821072396081d7dfd7194947772a682d7e212242..4e38f87a0edeabd6aa1ec01af765303634dc8f9a 100644 (file)
@@ -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;
index 65e8934315da2067e065986563db22d730b73ac9..6dcba7fea54d193b2736606111cebdaf656001f2 100644 (file)
@@ -3857,10 +3857,7 @@ SaveWorkspaceResources(
        XtFree(data);
    }
 
-   if (buffer)
-   {
-       XtFree(buffer);
-   }
+   XtFree(buffer);
 
 } /* END OF FUNCTION SaveWorkspaceResources */