dtcreate: Resolve coverity issues
authorPeter Howkins <flibble@users.sf.net>
Fri, 30 Mar 2018 22:35:39 +0000 (23:35 +0100)
committerPeter Howkins <flibble@users.sf.net>
Fri, 30 Mar 2018 22:35:39 +0000 (23:35 +0100)
cde/programs/dtcreate/CreateActionAppShell.c
cde/programs/dtcreate/OpenFile.c
cde/programs/dtcreate/af_aux.c
cde/programs/dtcreate/cmncbs.c
cde/programs/dtcreate/cmnrtns.c
cde/programs/dtcreate/fileio.c
cde/programs/dtcreate/icon_selection_dialog.c
cde/programs/dtcreate/main.c
cde/programs/dtcreate/parser.c

index 8d62812d5341ffa76ed9328839e2dc66973dfe9b..d4987e5f3a13fa83b5892e45977117433cdda82e 100644 (file)
@@ -319,7 +319,6 @@ What do you want to do?";
                               "Cancel Save", questionCB_CancelSave,
                               (char *)NULL, (XtCallbackProc)NULL);
          XtFree(bufPtr);
-         XtFree(pszActionFile);
           bHaveError = True;
        }
 
@@ -337,6 +336,8 @@ What do you want to do?";
     }
 
   }
+
+  XtFree(pszActionFile);
 }
 
 static  void    activateCB_CA_FiletypesDelete( Widget UxWidget,
@@ -540,7 +541,7 @@ static Widget   _Uxbuild_CreateActionAppShell(void)
             _UxParent = UxTopLevel;
         }
 
-       strcpy(titleBuf, GETMESSAGE(3, 10, "Create Action"));
+       snprintf(titleBuf, sizeof(titleBuf), "%s", GETMESSAGE(3, 10, "Create Action"));
         CreateActionAppShell = XtVaCreatePopupShell( "CreateActionAppShell",
                         applicationShellWidgetClass,
                         _UxParent,
@@ -624,7 +625,7 @@ static Widget   _Uxbuild_CreateActionAppShell(void)
         /*
         mnemonic = GETMESSAGE(2, 21, "N");
         */
-        strcpy(mnemonic, GETMESSAGE(2, 21, "N"));
+        snprintf(mnemonic, sizeof(mnemonic), "%s", GETMESSAGE(2, 21, "N"));
         CA_MB_FileNew = XtVaCreateManagedWidget( "CA_MB_FileNew",
                         xmPushButtonWidgetClass,
                         CA_MB_FileOption,
@@ -639,7 +640,7 @@ static Widget   _Uxbuild_CreateActionAppShell(void)
         /*
         mnemonic = GETMESSAGE(2, 16, "O");
         */
-        strcpy(mnemonic, GETMESSAGE(2, 16, "O"));
+        snprintf(mnemonic, sizeof(mnemonic), "%s", GETMESSAGE(2, 16, "O"));
         CA_MB_FileOpen = XtVaCreateManagedWidget( "CA_MB_FileOpen",
                         xmPushButtonWidgetClass,
                         CA_MB_FileOption,
@@ -654,7 +655,7 @@ static Widget   _Uxbuild_CreateActionAppShell(void)
         /*
         mnemonic = GETMESSAGE(2, 26, "S");
         */
-        strcpy(mnemonic, GETMESSAGE(2, 26, "S"));
+        snprintf(mnemonic, sizeof(mnemonic), "%s", GETMESSAGE(2, 26, "S"));
         CA_MB_FileSave = XtVaCreateManagedWidget( "CA_MB_FileSave",
                         xmPushButtonWidgetClass,
                         CA_MB_FileOption,
@@ -675,7 +676,7 @@ static Widget   _Uxbuild_CreateActionAppShell(void)
         /*
         mnemonic = GETMESSAGE(2, 31, "x");
         */
-        strcpy(mnemonic, GETMESSAGE(2, 31, "x"));
+        snprintf(mnemonic, sizeof(mnemonic), "%s", GETMESSAGE(2, 31, "x"));
         CA_MB_FileExit = XtVaCreateManagedWidget( "CA_MB_FileExit",
                         xmPushButtonWidgetClass,
                         CA_MB_FileOption,
@@ -690,7 +691,7 @@ static Widget   _Uxbuild_CreateActionAppShell(void)
         /*
         mnemonic = GETMESSAGE(2, 11, "F");
         */
-        strcpy(mnemonic, GETMESSAGE(2, 11, "F"));
+        snprintf(mnemonic, sizeof(mnemonic), "%s", GETMESSAGE(2, 11, "F"));
         CA_MB_FileTop = XtVaCreateManagedWidget( "CA_MB_FileTop",
                         xmCascadeButtonWidgetClass,
                         CA_MenuBar,
@@ -717,7 +718,7 @@ static Widget   _Uxbuild_CreateActionAppShell(void)
         /*
          * Creation of CA_MB_HelpOverview
         */
-        strcpy(mnemonic, GETMESSAGE(2, 61, "v"));
+        snprintf(mnemonic, sizeof(mnemonic), "%s", GETMESSAGE(2, 61, "v"));
         CA_MB_HelpOverview = XtVaCreateManagedWidget( "CA_MB_HelpOverview",
                         xmPushButtonWidgetClass,
                         CA_MB_HelpOption,
@@ -732,7 +733,7 @@ static Widget   _Uxbuild_CreateActionAppShell(void)
         /*
          * Creation of CA_MB_HelpTasks
         */
-        strcpy(mnemonic, GETMESSAGE(2, 71, "T"));
+        snprintf(mnemonic, sizeof(mnemonic), "%s", GETMESSAGE(2, 71, "T"));
         CA_MB_HelpTasks = XtVaCreateManagedWidget( "CA_MB_HelpTasks",
                         xmPushButtonWidgetClass,
                         CA_MB_HelpOption,
@@ -749,7 +750,7 @@ static Widget   _Uxbuild_CreateActionAppShell(void)
         /*
         mnemonic = GETMESSAGE(2, 66, "T");
         */
-        strcpy(mnemonic, GETMESSAGE(2, 66, "T"));
+        snprintf(mnemonic, sizeof(mnemonic), "%s", GETMESSAGE(2, 66, "T"));
         CA_MB_HelpTOC = XtVaCreateManagedWidget( "CA_MB_HelpTOC",
                         xmPushButtonWidgetClass,
                         CA_MB_HelpOption,
@@ -761,7 +762,7 @@ static Widget   _Uxbuild_CreateActionAppShell(void)
         /*
         * Creation of CA_MB_HelpReference
         */
-        strcpy(mnemonic, GETMESSAGE(2, 76, "R"));
+        snprintf(mnemonic, sizeof(mnemonic), "%s", GETMESSAGE(2, 76, "R"));
         CA_MB_HelpReference = XtVaCreateManagedWidget( "CA_MB_HelpReference",
                         xmPushButtonWidgetClass,
                         CA_MB_HelpOption,
@@ -784,7 +785,7 @@ static Widget   _Uxbuild_CreateActionAppShell(void)
         /*
          * Creation of CA_MB_HelpUsing
          */
-        strcpy(mnemonic, GETMESSAGE(2, 81, "U"));
+        snprintf(mnemonic, sizeof(mnemonic), "%s", GETMESSAGE(2, 81, "U"));
         CA_MB_HelpUsing = XtVaCreateManagedWidget( "CA_MB_HelpUsing",
                         xmPushButtonWidgetClass,
                         CA_MB_HelpOption,
@@ -807,7 +808,7 @@ static Widget   _Uxbuild_CreateActionAppShell(void)
         /*
          * Creation of CA_MB_HelpAbout
          */
-        strcpy(mnemonic, GETMESSAGE(2, 86, "A"));
+        snprintf(mnemonic, sizeof(mnemonic), "%s", GETMESSAGE(2, 86, "A"));
         CA_MB_HelpAbout = XtVaCreateManagedWidget( "CA_MB_HelpAbout",
                         xmPushButtonWidgetClass,
                         CA_MB_HelpOption,
@@ -822,7 +823,7 @@ static Widget   _Uxbuild_CreateActionAppShell(void)
         /*
          * Creation of CA_MB_HelpTop
          */
-        strcpy(mnemonic, GETMESSAGE(2, 54, "H"));
+        snprintf(mnemonic, sizeof(mnemonic), "%s", GETMESSAGE(2, 54, "H"));
         CA_MB_HelpTop = XtVaCreateManagedWidget( "CA_MB_HelpTop",
                         xmCascadeButtonWidgetClass,
                         CA_MenuBar,
@@ -848,7 +849,7 @@ static Widget   _Uxbuild_CreateActionAppShell(void)
                         NULL );
 
         /* Creation of ColorMonoOption */
-        strcpy(mnemonic, GETMESSAGE(2, 50, "M"));
+        snprintf(mnemonic, sizeof(mnemonic), "%s", GETMESSAGE(2, 50, "M"));
         ColorMonoOption = XtVaCreateManagedWidget( "ColorMonoOption",
                         xmToggleButtonWidgetClass,
                         CA_MB_OptionsOption,
@@ -864,7 +865,7 @@ static Widget   _Uxbuild_CreateActionAppShell(void)
 
 
         /* Creation of CA_MB_OptionTop */
-        strcpy(mnemonic, GETMESSAGE(2, 36, "O"));
+        snprintf(mnemonic, sizeof(mnemonic), "%s", GETMESSAGE(2, 36, "O"));
         CA_MB_OptionTop = XtVaCreateManagedWidget( "CA_MB_OptionTop",
                         xmCascadeButtonWidgetClass,
                         CA_MenuBar,
index 60f4137745539679020ca69c53850953a5177e0f..cc62faffb71b61b6ac1c32a87fb88e63fc04e60c 100644 (file)
@@ -77,7 +77,7 @@ static  void    okCallback_OpenFile( Widget UxWidget,
         _UxCOpenFile                     *UxSaveCtx, *UxContext;
         XmFileSelectionBoxCallbackStruct *cbs;
         /*char        *text;*/
-        int         rc;
+        int         rc = 1; /* 1 = OpenDefinitionFile() failure */
         ActionData  ADTmp;
 
         UxSaveCtx = UxOpenFileContext;
index 561925c9c7f8ab14eb706af66cb6025a65706723..76c4757b6c60e6963cd5b8e6487f893ffb5543b3 100644 (file)
@@ -263,7 +263,6 @@ void getAF_Icons(FiletypeData *pFiletypedata)
   /* Tiny Bitmap                                                 */
   /***************************************************************/
   if ( (pIconData->bmDirtyBit) &&
-       (pIconData->bmFileName) &&
        (strlen(pIconData->bmFileName)) ) {
      pFiletypedata->pszTinyBmIcon = XtMalloc(strlen(pIconData->bmFileName) + 1);
      if (pFiletypedata->pszTinyBmIcon) {
index 7fb8a828df02eece253316124adc2d6107f42507..5046aeebfec774bc3312afb32197b2a5f3e87140 100644 (file)
@@ -271,8 +271,7 @@ void DisplayHelpDialog(Widget wid, XtPointer client_data, XtPointer cbs)
   sprintf(pszTitle, "%s  -  %s", GETMESSAGE(3, 10, "Create Action"),
           GETMESSAGE(2, 53, "Help"));
   */
-  sprintf(pszTitle, "%s  -  ", GETMESSAGE(3, 10, "Create Action"));
-  strcat(pszTitle, GETMESSAGE(2, 53, "Help"));
+  snprintf(pszTitle, sizeof(pszTitle), "%s  -  %s", GETMESSAGE(3, 10, "Create Action"), GETMESSAGE(2, 53, "Help"));
   XtSetArg(args[i], XmNtitle, pszTitle); i++;
 
   /***********************************************************************/
index 84a160d368e7074f61e12e3c541f323b6592fb71..521391cf5a055f84ac6f4b780d2c1f8c3efed212 100644 (file)
@@ -292,7 +292,7 @@ void load_icons (Widget wid, XtPointer client_data,
 /******************************************************************************/
 void GetWidgetTextString (Widget wid, char **ppszText)
 {
-  char *pszTmp;
+  char *pszTmp = NULL;
 
   if (*ppszText) {
      XtFree(*ppszText);
@@ -690,12 +690,12 @@ void SetIconData(Widget wid, char *pszIconFile, enum icon_size_range enumIconSiz
 #endif
 
   pszName = CreateIconName((char *)NULL, pszIconFile, enumIconSize, PIXMAP_EXT, FALSE);
-  strcpy(pmFileName, pszName);
-  if (pszName) XtFree(pszName);
+  snprintf(pmFileName, sizeof(pmFileName), "%s", pszName);
+  XtFree(pszName);
 
   pszName = CreateIconName((char *)NULL, pszIconFile, enumIconSize, BITMAP_EXT, FALSE);
-  strcpy(bmFileName, pszName);
-  if (pszName) XtFree(pszName);
+  snprintf(bmFileName, sizeof(bmFileName), "%s", pszName);
+  XtFree(pszName);
 
   pIconData = GetIconDataFromWid(wid);
   if (pIconData) {
@@ -711,7 +711,6 @@ void SetIconData(Widget wid, char *pszIconFile, enum icon_size_range enumIconSiz
      strcpy(pIconData->pmFileName, pmFileName);
 
      if ( (pIconData->bmDirtyBit) &&
-          (pIconData->bmFileName) &&
           (strlen(pIconData->bmFileName)) ) {
 #ifdef DEBUG
         printf("SetIconData: unlink '%s'\n", pIconData->bmFileName);  /* debug */
index 9ba48bea61b2af767dadf8ed41a85d82a10c0db0..ba1a0b3e679a7799041ccb311e5c7a30c46b9c77 100644 (file)
@@ -614,7 +614,9 @@ ushort WriteDefinitionFile(char *pszFile, ActionData *pAD)
   }
   SetCookie(fp);
   if (fp) fclose(fp);
-  chmod(pszFile, 0644);
+  if(pszFile) {
+    chmod(pszFile, 0644);
+  }
   return(0);
 }
 
@@ -655,7 +657,7 @@ ushort WriteActionFile(ActionData *pAD)
   /***************************************************************************/
   /* Open action file for writing.                                           */
   /***************************************************************************/
-  if (pszFile && (fp = fopen(pszFile, "w")) == NULL) {
+  if (pszFile == NULL || (fp = fopen(pszFile, "w")) == NULL) {
 #ifdef DEBUG
     printf("Can not open file.\n"); /* debug */
 #endif
@@ -694,7 +696,7 @@ ushort WriteActionFile(ActionData *pAD)
   fprintf(fp, "echo \"Common Desktop Environment Dt action\"\n");
   fprintf(fp, "\n");
 
-  if (fp) fclose(fp);
+  fclose(fp);
   chmod(pszFile, 0755);
   return(0);
 }
@@ -746,7 +748,7 @@ int OpenDefinitionFile(char *pszFile, ActionData *pAD)
 
 {
   FILE       *fp = (FILE *)NULL;
-  int        rc;
+  int        rc = 1;
   char       *msgPtr, *fmtPtr, *errPtr;
 
   /***************************************************************************/
@@ -789,10 +791,11 @@ int OpenDefinitionFile(char *pszFile, ActionData *pAD)
        sprintf(errPtr, fmtPtr, msgPtr, pszFile);
         display_error_message(CreateActionAppShell, errPtr);
        XtFree(errPtr);
+       fclose(fp);
         return(1);
      }
   }
-  if (fp) fclose(fp);
+  fclose(fp);
   return(rc);
 }
 
index 79b32f982062e80030577a21e717ea35055e66fb..c0bff51f4ce97d8546e8938d05bab58561978966 100644 (file)
@@ -790,7 +790,7 @@ void  update_container_contents (char *filter)
     XmeFlushIconFileCache(NULL);
 
     for (lcv = 0; lcv < count; lcv++) {
-       sprintf (iconfile, "%s%s", path, filelist[lcv]->d_name);
+       snprintf(iconfile, sizeof(iconfile), "%s%s", path, filelist[lcv]->d_name);
        ptr = strstr(filelist[lcv]->d_name, ".m.");
        if (ptr) {
           *ptr = '\0';
@@ -813,7 +813,7 @@ void  update_container_contents (char *filter)
   /* This is the empty directory case                               */
   /******************************************************************/
   } else {
-       strcpy(iconfile, GETMESSAGE(11, 60, "[Empty]"));
+       snprintf(iconfile, sizeof(iconfile), "%s", GETMESSAGE(11, 60, "[Empty]"));
        xmstring = XmStringCreateLocalized(iconfile);
        XtVaSetValues ((Widget) icons_in_container[0],
                              XmNstring,        xmstring,
@@ -841,6 +841,7 @@ void  update_container_contents (char *filter)
   }
 
   XtManageChild (icon_scrolled_container);
+  free(path);
   return;
 
 }
@@ -1261,6 +1262,7 @@ static  void    defaultActionCB_dir_scrolled_list( Widget UxWidget,
     filter = (char *)XmStringToText (listcb->item);
     apply_filter (filter);
  /* XtManageChild (icon_scrolled_win);  */
+    free(filter);
   }
   UxIcon_selection_dialogContext = UxSaveCtx;
 }
index b9deaa56752d695f1b28e403245b5b66804d8bcc..aae400b9840c3e01a4b639349b702907d1cf503e 100644 (file)
@@ -514,7 +514,6 @@ void RemoveTmpIconFiles( void )
         unlink(maskFile);
      }
      if ( (IconDataList[i]->bmDirtyBit) &&
-          (IconDataList[i]->bmFileName) &&
           (strlen(IconDataList[i]->bmFileName)) ) {
 #ifdef DEBUG
         printf("RemoveTmpIconFiles: unlink '%s'\n", IconDataList[i]->bmFileName);  /* debug */
@@ -863,7 +862,7 @@ Tt_callback_action IconEdit_tt_handler( Tt_message m, Tt_pattern p )
            if (tmp) {
               tmp1 = strstr(tmp, "};");
            }
-           sprintf(tmpbuf, "%s_m", tmpIconFile);
+           snprintf(tmpbuf, sizeof(tmpbuf), "%s_m", tmpIconFile);
            if (tmp1) {
               tmp1 += 2;                       /* Go one char past the ";" */
 #ifdef DEBUG
@@ -1067,6 +1066,7 @@ void UxDoEditPixmap(Widget wid, char *fname)
                  display_error_message(XtParent(wid), errPtr);
                 XtFree(errPtr);
                  XtFree(mname);
+                 if (fd1 > -1) close(fd1);
                  return;
               } else {
                  /***************************************/
@@ -1103,6 +1103,8 @@ void UxDoEditPixmap(Widget wid, char *fname)
              XtFree(errPtr);
               if (mname) XtFree(mname);
               XtFree((char *) buffer);
+              if (fd1 > -1) close(fd1);
+              if (fd2 > -1) close(fd2);
               return;
            }
            if (lenFile2) {
@@ -1127,11 +1129,13 @@ void UxDoEditPixmap(Widget wid, char *fname)
                 XtFree(errPtr);
                  XtFree((char *) buffer);
                  if (mname) XtFree(mname);
+                 if (fd1 > -1) close(fd1);
+                 if (fd2 > -1) close(fd2);
                  return;
               }
            }
-           if (fd1 > -1) close(fd1);
-           if (fd2 > -1) close(fd2);
+           if (fd1 > -1) close(fd1); fd1 = -1;
+           if (fd2 > -1) close(fd2); fd2 = -1;
 
 #ifdef DEBUG
            printf("final buffer = '%s'\n", buffer); /* debug */
@@ -1171,6 +1175,9 @@ void UxDoEditPixmap(Widget wid, char *fname)
   TurnOnHourGlassAllWindows();
   ttRc = tt_message_send( m );
   DieFromToolTalkError( UxTopLevel, "tt_message_send", ttRc );
+
+  if (fd1 > -1) close(fd1);
+  if (fd2 > -1) close(fd2);
 }
 #endif  /* __TOOLTALK */
 
index 400834fa93d1ea9fb63913f9a74d1cca97fa40c1..13e855fea468695f5cbae60a64e101a79ed48075 100644 (file)
@@ -647,6 +647,7 @@ FiletypeData  **ppFiletypeData,**ppnewFiletypeData;
                 ppFiletypeData[nfiletypes] = 0;
             /* return number of filetypes */
             *nftypes = nfiletypes+1;
+            free(execstr);
             return ppFiletypeData;
 
         }
@@ -707,8 +708,7 @@ GetKeywordValuePairs(char *s, int *id, int table)
         if (!args[1])
         {
            int szArgs1 = strlen(s) + 1;
-            if(s)
-               args[1] = (char *)malloc (szArgs1);
+            args[1] = (char *)malloc (szArgs1);
             if (!args[1])
             {
                 if(args[0])
@@ -881,7 +881,7 @@ int  done=FALSE, argfound=FALSE,promptfound=FALSE;
                            continue;
                       }
                 }
-                else if (s1 && *s1)
+                else if (*s1)
                 {
                      strcat(exec_args[0],s1);
                      if(argbuf)   { free(argbuf); argbuf = NULL; }
@@ -1018,8 +1018,10 @@ char    *s1,*tmp,*s2,buf[10],*cts;
                pFtD->fsFlags|=CA_FT_CNTLONG;
            else if ( !strcmp(buf,"short") )
                pFtD->fsFlags|=CA_FT_CNTSHORT;
-           else
+           else {
+               free(cts);
                return (-1);
+           }
         }
         while( *tmp && isspace(*tmp) )  tmp++;
         s2=tmp;