1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-02-15 04:32:24 +00:00

dtpad: resove coverity issues

This commit is contained in:
Peter Howkins 2018-04-11 18:05:06 +01:00
parent 56b53a30a1
commit db88cb0d13
5 changed files with 14 additions and 15 deletions

View file

@ -225,7 +225,7 @@ SetSaveAsDirAndFile(Editor *pPad)
strcpy(dirbuf, pPad->fileStuff.pathDir);
/* -----> make sure dir ends in '/' */
if (dirbuf[0] != (char )'\0') {
if (dirbuf[strlen(dirbuf) - 1] != (char)'/')
if (strlen(dirbuf) && dirbuf[strlen(dirbuf) - 1] != (char)'/')
strcat(dirbuf, "/");
} else {
getcwd(dirbuf, MAX_DIR_PATH_LEN - 16);

View 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 {

View 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';

View 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);
}
}

View 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,13 +427,8 @@ 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);
}