dtpad: resove coverity issues
authorPeter Howkins <flibble@users.sf.net>
Wed, 11 Apr 2018 17:05:06 +0000 (18:05 +0100)
committerPeter Howkins <flibble@users.sf.net>
Wed, 11 Apr 2018 17:05:06 +0000 (18:05 +0100)
cde/programs/dtpad/fileDlg.c
cde/programs/dtpad/fileIo.c
cde/programs/dtpad/printOutput.c
cde/programs/dtpad/printSetup.c
cde/programs/dtpad/ttMsgSupport.c

index b17dae36a9c7c02a32799a849e1d40177da5b973..5c882e19e11e58afdf108944aa814b695187f64e 100644 (file)
@@ -225,8 +225,8 @@ SetSaveAsDirAndFile(Editor *pPad)
            strcpy(dirbuf, pPad->fileStuff.pathDir);
        /* -----> make sure dir ends in '/' */
        if (dirbuf[0] != (char )'\0') {
-           if (dirbuf[strlen(dirbuf) - 1] != (char)'/')
-               strcat(dirbuf, "/");
+           if (strlen(dirbuf) && dirbuf[strlen(dirbuf) - 1] != (char)'/')
+                 strcat(dirbuf, "/");
        } else {
            getcwd(dirbuf, MAX_DIR_PATH_LEN - 16);
            strcat(dirbuf, "/");
index cd5db3309637b6bef694bd9ab83afdda593a340d..c5619078c87e2a417f3e083b13304a357efee039 100644 (file)
@@ -314,7 +314,7 @@ AddPound(
                    strcat(returnBuf, "#");
        } else {
            sprintf(returnBuf, "#%s", tempBuf);
-           if(returnBuf[strlen(returnBuf) - 1] != (char)'#')
+           if(strlen(returnBuf) && returnBuf[strlen(returnBuf) - 1] != (char)'#')
                strcat(returnBuf, "#");
        }
     } else {
index aa12771f641f73ab16cf4e729fc0909b68c798d4..bf5ff4110ad79ffe9674463e432fd89ddd5575bf 100644 (file)
@@ -804,7 +804,10 @@ _poGetFileContents(char **contents, char *file)
     if( (fp = fopen(file, "r")) == NULL )
       return DtEDITOR_UNREADABLE_FILE;
 
-    stat(file, &statbuf);
+    if(stat(file, &statbuf) == -1) {
+      fclose(fp);
+      return DtEDITOR_UNREADABLE_FILE;
+    }
     nbytes = statbuf.st_size;
 
     /* 
@@ -814,8 +817,10 @@ _poGetFileContents(char **contents, char *file)
      * copy of the data before actually putting it into the widget.
      */
     buf = (char *) malloc(nbytes + 1);
-    if (buf == NULL)
+    if (buf == NULL) {
+         fclose(fp);
       return DtEDITOR_INSUFFICIENT_MEMORY;
+    }
 
     nbytes = fread(buf, sizeof(char), nbytes, fp);
     buf[nbytes] = '\0';
index 48277032d70ee1ff1cae1ff5842cb258e86a3127..181b1a1bef48f778fcbc61df1135d289e8ead3be 100644 (file)
@@ -430,8 +430,8 @@ _psGetResourceFileName(PrintSetup *pSetup)
     saveFile = PS_DEFAULT_RESOURCE_FILE;
     if (! DtSessionSavePath(topLevelWithWmCommand, &savePath, &saveFile))
     {
-       sprintf(
-               buffer, "%s/%s/%s",
+       snprintf(
+               buffer, sizeof(buffer), "%s/%s/%s",
                getenv(PS_HOME_ENV_VARIABLE),
                DtPERSONAL_TMP_DIRECTORY,
                PS_DEFAULT_RESOURCE_FILE);
@@ -853,7 +853,7 @@ _psAttachPrintSetupDialog(PrintSetup *pSetup, Editor *pPad)
              filename = pSetup->docName;
            else
              filename++;
-            sprintf(path, "%s/%s.ps", dirname, filename);
+            snprintf(path, sizeof(path), "%s/%s.ps", dirname, filename);
             XtVaSetValues(pSetup->dtprintSetup, DtNfileName, path, NULL);
         }
     }
index 373aeb66dce0287e05b795d4b83ea4403f4add88..ad6e997a39d48b99c8ac544591a1a00ae999225f 100644 (file)
@@ -248,7 +248,6 @@ TTmedia_ptype_declareCB(
     DtEditorErrorCode   errorCode;
     Boolean foundPad = False;
     char *context = (char *)NULL;
-    char *oldFileName = (char *)NULL;
     Boolean  isCurrentlyVisible = False;
     int mark = tt_mark();
     char *localPath = tt_message_file(m);
@@ -428,14 +427,9 @@ TTmedia_ptype_declareCB(
     /* -----> Create GUI components of Editor instance, set resouces,
      *        map window and load file (if specified). */
     if (!foundPad) {
-      if (oldFileName != (char *)NULL)
-       XtFree(oldFileName);
-
       RealizeNewPad(pPad);             /* pPad->mainWindow is created here */
     } else {
-       if (oldFileName != (char *)NULL)
-         XtFree(oldFileName);
-       ManageOldPad(pPad, isCurrentlyVisible);
+      ManageOldPad(pPad, isCurrentlyVisible);
     }
                                
     /* -----> Accept the message.