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, "/");
strcat(returnBuf, "#");
} else {
sprintf(returnBuf, "#%s", tempBuf);
- if(returnBuf[strlen(returnBuf) - 1] != (char)'#')
+ if(strlen(returnBuf) && returnBuf[strlen(returnBuf) - 1] != (char)'#')
strcat(returnBuf, "#");
}
} else {
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;
/*
* 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';
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);
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);
}
}
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);
/* -----> 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.