libDtWidget: Resolve some Coverity warnings
authorPeter Howkins <flibble@users.sf.net>
Fri, 30 Mar 2018 23:15:05 +0000 (00:15 +0100)
committerPeter Howkins <flibble@users.sf.net>
Fri, 30 Mar 2018 23:15:05 +0000 (00:15 +0100)
cde/lib/DtWidget/Control.c
cde/lib/DtWidget/EditCalls.c
cde/lib/DtWidget/MenuButton.c
cde/lib/DtWidget/SearchCalls.c
cde/lib/DtWidget/TitleBox.c

index b4a35a644ebe6f0688612e62022efe62a631ff48..fa30d1f961c9d05f21fc1eb4cefdb27bcc504866 100644 (file)
@@ -2085,7 +2085,7 @@ ReplaceJPDate(char *date, char *jpstr, int wday)
         free(s);
         return;
     }
-    strcpy(abday, nl_langinfo(ABDAY_1 + wday));
+    snprintf(abday, sizeof(abday), "%s", nl_langinfo(ABDAY_1 + wday));
     if((rp = strstr(date, abday)) != NULL) {
         for(i = 0, j = 0, sp = date; date[j] != '\0'; sp++) {
             if(sp == rp) {
index 9a9b29eab7404f60529331ec75a35638ea40c5b7..0837d1d97fefa596c462f513a0f57caea89737b3 100644 (file)
@@ -304,8 +304,7 @@ SetUndoDeletionState(
            strcat(M_deletedText(pPriv), oldUndo);
            M_deletionStart(pPriv) = cb->startPos;
         }
-        if(oldUndo != (char *)NULL)
-           XtFree(oldUndo);
+        XtFree(oldUndo);
     }
     else 
     {
@@ -323,8 +322,7 @@ SetUndoDeletionState(
        M_insertionLength(pPriv) = 0;
     }
 
-    if( pDeletedText != (char *)NULL )
-      XtFree( pDeletedText );
+    XtFree( pDeletedText );
 } /* SetUndoDeletionState */
 
 /*
index 96fbbadac6d8d9fd8d6076580a9781d71390206b..74f98a882faeef123d866d1a23c6c301f2dc8326 100644 (file)
@@ -961,7 +961,7 @@ Initialize(
                                PopupCallback, (XtPointer)new_w);
        }
 
-       if (name) XtFree(name);
+       XtFree(name);
 }
 
 
index ea8ffebe69dbb22f568296d7532cf2c1ed72faac..722cbcb02f6476d1ebe5414266f08f2649f9e7d9 100644 (file)
@@ -482,8 +482,7 @@ SearchForString(
            return (int)pos;
        }
 
-       if (word  != (char *)NULL)
-         XtFree(word);
+       XtFree(word);
     }
 
     return -1;
@@ -812,8 +811,7 @@ _DtEditorDialogSearchCB(
         * Find/Change mode
         * Free the existing search string and get the new one.
         */
-       if (M_search_string(pPriv)) 
-           XtFree(M_search_string(pPriv));
+       XtFree(M_search_string(pPriv));
        M_search_string(pPriv) = XmTextFieldGetString( M_findText(pPriv) );
 
        /*
@@ -869,8 +867,7 @@ _DtEditorDialogSearchCB(
           if( pString != (char *)NULL && *pString != (char)'\0' ) 
              _DtEditorSetReplaceSensitivity( pPriv, True );
 
-          if(pString != (char *)NULL)
-            XtFree(pString);
+          XtFree(pString);
        }
        else {
         /* 
@@ -918,8 +915,7 @@ _DtEditorDialogReplaceCB(
         * Find/Change mode
         * Free the existing Change To string and get the new one.
         */
-       if (M_replace_string(pPriv)) 
-           XtFree(M_replace_string(pPriv));
+       XtFree(M_replace_string(pPriv));
        M_replace_string(pPriv) = XmTextFieldGetString(M_replaceText(pPriv));
 
        DtEditorChange( (Widget)pPriv, (DtEditorChangeValues *)NULL, 
@@ -979,15 +975,13 @@ _DtEditorDialogReplaceAllCB(
         * Find/Change mode
         * Free any existing search string before getting the current one.
         */
-       if (M_search_string(pPriv)) 
-           XtFree(M_search_string(pPriv));
+       XtFree(M_search_string(pPriv));
        M_search_string(pPriv) = XmTextFieldGetString(M_findText(pPriv));
 
        /*
         * Free the existing Change To string and get the new one.
         */
-       if (M_replace_string(pPriv)) 
-           XtFree(M_replace_string(pPriv));
+       XtFree(M_replace_string(pPriv));
        M_replace_string(pPriv) = XmTextFieldGetString(M_replaceText(pPriv));
 
        /* 
@@ -1018,8 +1012,7 @@ _DtEditorDialogReplaceAllCB(
        changeValues.changeTo = XmTextFieldGetString(M_replaceText(pPriv));
        DtEditorChange((Widget)pPriv, &changeValues, DtEDITOR_ALL_OCCURRENCES);
 
-       if( changeValues.changeTo != (char *)NULL )
-         XtFree( changeValues.changeTo );
+       XtFree( changeValues.changeTo );
 
     }
 
@@ -1061,8 +1054,7 @@ _DtEditorMisspelledSelectCB(
      * Get the selected word for use when the Find or Replace All button
      * is pressed.
      */
-    if (M_misspelled_string(editor)) 
-      XtFree(M_misspelled_string(editor));
+    XtFree(M_misspelled_string(editor));
 
     M_misspelled_string(editor) = 
        _XmStringUngenerate(cb->item, NULL, XmCHARSET_TEXT, XmCHARSET_TEXT);
@@ -1181,8 +1173,7 @@ _DtEditorFindTextChangedCB(
          */
         defaultButton = M_search_findBtn(editor);
     }
-    if(pString != (char *)NULL)
-       XtFree(pString);
+    XtFree(pString);
 
     /*
      * Set the default button 
@@ -1247,8 +1238,7 @@ _DtEditorReplaceTextChangedCB(
          if ( M_misspelled_found(editor) )
             _DtEditorSetReplaceSensitivity(editor, True );
 
-       if(pString != (char *)NULL)
-         XtFree(pString);
+       XtFree(pString);
 
       }
 
index b76b42956330452177ab47e30f5841f254874ad7..dc6ca481d75237e28a5c9a75a2b3ffe59ef1f3ee 100644 (file)
@@ -762,7 +762,7 @@ Redisplay(
 
 /*     Redisplay work area.
 */
-       if (work_area && XmIsGadget (work_area) && XtIsManaged (work_area))
+       if (XmIsGadget (work_area) && XtIsManaged (work_area))
        {
                XtExposeProc expose;
                _DtProcessLock();