From db88cb0d13139f100574927aaa909de911e384ff Mon Sep 17 00:00:00 2001 From: Peter Howkins Date: Wed, 11 Apr 2018 18:05:06 +0100 Subject: [PATCH] dtpad: resove coverity issues --- cde/programs/dtpad/fileDlg.c | 4 ++-- cde/programs/dtpad/fileIo.c | 2 +- cde/programs/dtpad/printOutput.c | 9 +++++++-- cde/programs/dtpad/printSetup.c | 6 +++--- cde/programs/dtpad/ttMsgSupport.c | 8 +------- 5 files changed, 14 insertions(+), 15 deletions(-) diff --git a/cde/programs/dtpad/fileDlg.c b/cde/programs/dtpad/fileDlg.c index b17dae36..5c882e19 100644 --- a/cde/programs/dtpad/fileDlg.c +++ b/cde/programs/dtpad/fileDlg.c @@ -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, "/"); diff --git a/cde/programs/dtpad/fileIo.c b/cde/programs/dtpad/fileIo.c index cd5db330..c5619078 100644 --- a/cde/programs/dtpad/fileIo.c +++ b/cde/programs/dtpad/fileIo.c @@ -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 { diff --git a/cde/programs/dtpad/printOutput.c b/cde/programs/dtpad/printOutput.c index aa12771f..bf5ff411 100644 --- a/cde/programs/dtpad/printOutput.c +++ b/cde/programs/dtpad/printOutput.c @@ -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'; diff --git a/cde/programs/dtpad/printSetup.c b/cde/programs/dtpad/printSetup.c index 48277032..181b1a1b 100644 --- a/cde/programs/dtpad/printSetup.c +++ b/cde/programs/dtpad/printSetup.c @@ -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); } } diff --git a/cde/programs/dtpad/ttMsgSupport.c b/cde/programs/dtpad/ttMsgSupport.c index 373aeb66..ad6e997a 100644 --- a/cde/programs/dtpad/ttMsgSupport.c +++ b/cde/programs/dtpad/ttMsgSupport.c @@ -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. -- 2.25.1