dtmail: Further Coverity fixes

This commit is contained in:
Peter Howkins
2018-04-24 02:38:56 +01:00
parent 9088d6b54e
commit 3cf92f3741
26 changed files with 113 additions and 87 deletions

View File

@@ -179,8 +179,10 @@ void AlternatesListUiItem::writeFromSourceToUi()
list_str = strdup("");
}
if ((buf = (char *) malloc(strlen(list_str) + 1)) == NULL)
if ((buf = (char *) malloc(strlen(list_str) + 1)) == NULL) {
free((void *) list_str);
return;
}
strcpy(buf, (char *)list_str);
if((token = (char *) strtok(buf, " ")))

View File

@@ -188,6 +188,10 @@ AttachArea::AttachArea (
_editCmdList = NULL;
_size_selected_label = NULL;
_format_button = NULL;
_descriptionDialog = NULL;
_no_attachments_label = NULL;
_attachments_label = NULL;
_size_attachments_label = NULL;
}
@@ -702,6 +706,9 @@ AttachArea::addAttachment(
if (read(fd, buffer, (unsigned int) s.st_size) < 0) {
SafeClose(fd);
delete [] buf;
delete [] buffer;
delete [] errormsg;
return(NULL);
}
buffer[s.st_size] = 0;

View File

@@ -92,10 +92,10 @@ void CheckBoxUiItem::writeFromSourceToUi()
//
// This assumes that a non-null value means that the
// value is set and that a non-null means turn on the CB
if (strcmp(value, "") == 0)
options_checkbox_set_value(w, TRUE, this->dirty_bit);
else if (NULL == value || strcmp(value, "f") == 0)
if (NULL == value || strcmp(value, "f") == 0)
options_checkbox_set_value(w, FALSE, this->dirty_bit);
else if (strcmp(value, "") == 0)
options_checkbox_set_value(w, TRUE, this->dirty_bit);
free((void*) value);
}

View File

@@ -95,6 +95,11 @@ DmxMsg::DmxMsg (void)
addlInfo = NULL;
numBPs = 0;
cachedValues = DTM_FALSE;
msgHandle = NULL;
msgHeader.header_values = 0;
msgHeader.number_of_names = 0;
bodyParts = NULL;
isNew = DTM_FALSE;
return;
}

View File

@@ -218,6 +218,11 @@ DmxPrintOptions::DmxPrintOptions (
_propui_array_iterator = 0;
_parent = parent;
_prop_source = NULL;
_hdrftr_frame = NULL;
_margin_frame = NULL;
_msgsep_iom = NULL;
_prthdr_iom = NULL;
//
// Create form to hold the printing options

View File

@@ -116,7 +116,7 @@ DmxPrintSetup::DmxPrintSetup (
_filename = (char*) malloc(MAXPATHLEN+1);
if (NULL != _filename)
sprintf(_filename, "%s/dtmail_messages.ps", getenv("HOME"));
snprintf(_filename, MAXPATHLEN+1, "%s/dtmail_messages.ps", getenv("HOME"));
_printCB = printCB;
_cancelCB = cancelCB;

View File

@@ -254,10 +254,10 @@ Editor::set_message(DtMail::Message * msg,
}
bp->unlockContents(error);
firstBPHandled = DTM_TRUE;
if (attr) {
DtDtsFreeAttributeValue(attr);
attr = NULL;
}
}
if (attr) {
DtDtsFreeAttributeValue(attr);
attr = NULL;
}
free(type);
@@ -424,8 +424,7 @@ Editor::update_display_from_props(void)
value = strdup("24");
}
rows = (int) strtol(value, NULL, 10);
if (NULL != value)
free((void*) value);
free((void*) value);
set_rows(rows);
// If toolcols is set, overwrite the column width with "toolcols" value.

View File

@@ -2436,7 +2436,7 @@ MsgScrollingList::updateListItems(int current,
fprintf(stderr,
"dtmail: getMessageSummary: Couldn't get summary for msg # %d\n", m);
if ((msg == NULL) || (mbox == NULL))
if (msg == NULL)
{
// Error
;

View File

@@ -161,7 +161,7 @@ OptCmd::OptCmd ( char *name, char *label, int active, Widget parent) :
generalDialog = NULL;
_PrintingOptions = NULL;
_MailRetrievalOptions = NULL;
printing_pane_list = NULL;
}
void

View File

@@ -511,7 +511,7 @@ static char *tooltalk_save_buffer_to_file(
char *tmpdir = new char[MAXPATHLEN+1];
// 1. Get buffer content into file.
sprintf(tmpdir, "%s/%s", getenv("HOME"), DtPERSONAL_TMP_DIRECTORY);
snprintf(tmpdir, MAXPATHLEN+1, "%s/%s", getenv("HOME"), DtPERSONAL_TMP_DIRECTORY);
p = tempnam(tmpdir, "mail");
if (p == NULL)
{

View File

@@ -540,7 +540,7 @@ ConvertContainerCmd::post_dialog()
char * buf = new char[25];
sprintf(buf, "Converted: %3d%", 0);
sprintf(buf, "Converted: %3d%%", 0);
_dialog->post ("Mailer",
buf,
@@ -1660,7 +1660,7 @@ MoveCopyCmd::fileSelectedCallback2 (
// If a string was successfully extracted, call
// unifiedMailboxSelected to handle the file.
*selected = '\0';
if (NULL != dname) strcat(selected, dname);
if (NULL != dname) snprintf(selected, sizeof(selected), "%s", dname);
strcat(selected, fname);
obj->updateUnifiedData();
obj->unifiedMailboxSelected(
@@ -1852,7 +1852,7 @@ PrintCmd::printit( int silent )
DebugPrintf(1, "%s: printit\n", name());
// Create tmp file.
sprintf(tmpdir, "%s/%s", getenv("HOME"), DtPERSONAL_TMP_DIRECTORY);
snprintf(tmpdir, MAXPATHLEN+1, "%s/%s", getenv("HOME"), DtPERSONAL_TMP_DIRECTORY);
if ((p = tempnam(tmpdir, "dtmail")) == NULL) {
delete [] tmpdir;
return;
@@ -2471,9 +2471,9 @@ SaveAsTextCmd::writeTextFromScrolledList(int fd)
// Create temp file.
//
char *tmpdir = new char[MAXPATHLEN+1];
sprintf(tmpdir, "%s/%s", getenv("HOME"), DtPERSONAL_TMP_DIRECTORY);
snprintf(tmpdir, MAXPATHLEN+1, "%s/%s", getenv("HOME"), DtPERSONAL_TMP_DIRECTORY);
if ((tmppath = tempnam(tmpdir, "dtmail")) == NULL) {
sprintf(buf, GETMSG(DT_catd, 3, 51, "Unable to create %s."), tmpdir);
snprintf(buf, sizeof(buf), GETMSG(DT_catd, 3, 51, "Unable to create %s."), tmpdir);
_genDialog->setToErrorDialog(GETMSG(DT_catd, 3, 52, "Mailer"), buf);
helpId = DTMAILHELPNOCREATE;
_genDialog->post_and_return(helpId);
@@ -3393,7 +3393,7 @@ VacationCmd::stopVacation()
{
char *forwardfile = new char[MAXPATHLEN+1];
sprintf(forwardfile, "%s/%s", getenv("HOME"), _forwardFile);
snprintf(forwardfile, MAXPATHLEN+1, "%s/%s", getenv("HOME"), _forwardFile);
// Remove the current .forward file (it has vacation in it)
// Recover and replace the original backup forward file, if
@@ -3414,7 +3414,7 @@ VacationCmd::priorVacationRunning()
Boolean retval = FALSE;
char *forwardfile = new char[MAXPATHLEN+1];
sprintf(forwardfile, "%s/%s", getenv("HOME"), _forwardFile);
snprintf(forwardfile, MAXPATHLEN+1, "%s/%s", getenv("HOME"), _forwardFile);
if (SafeAccess(forwardfile, F_OK) != 0) {
delete [] forwardfile;
@@ -3732,6 +3732,7 @@ VacationCmd::handleForwardFile()
delete [] messagefile;
delete [] error_buf;
delete [] forwardfile;
SafeClose(bkup_fd);
SafeClose(fwd_fd);
return 1;
}
@@ -3754,6 +3755,7 @@ VacationCmd::handleForwardFile()
strlen(append_buf2)) {
// error
SafeClose(bkup_fd);
SafeClose(fwd_fd);
delete [] buf;
delete [] messagefile;
delete [] error_buf;
@@ -3831,7 +3833,7 @@ VacationCmd::recoverForwardFile(
return(-1);
}
if ((fd = SafeOpen(file, O_RDONLY)) == 0) {
if ((fd = SafeOpen(file, O_RDONLY)) == -1) {
delete [] buf;
return(-1);
}
@@ -3935,8 +3937,10 @@ VacationCmd::parseVacationMessage()
size_t map_size = (int) (buf.st_size +
(page_size - (buf.st_size % page_size)));
if (buf.st_size == 0)
if (buf.st_size == 0) {
SafeClose(fd);
return;
}
int free_buf = 0;
mbuf.size = buf.st_size;

View File

@@ -465,7 +465,7 @@ RoamMenuWindow::RoamMenuWindow (char *name) : MenuWindow ("dtmail", True)
_last_sorted_by = (SortBy) atoi(value);
free((void*) value);
if (NULL != buffer) XtFree(buffer);
XtFree(buffer);
}
@@ -4248,6 +4248,8 @@ RoamMenuWindow::syncViewAndStoreCallback(
RoamMenuWindow * rmw = (RoamMenuWindow *)client_data;
bval = rmw->syncViewAndStore(op, path, args);
va_end(args);
return(bval);
}
@@ -5113,7 +5115,7 @@ RoamMenuWindow::inList(char *filename, DtVirtArray<ContainerMenuCmd *> *list)
for (int i=0; i < list->length(); i++)
{
cmd = (*list)[i];
if (strcmp(filename, cmd->containerName()) == 0)
if (filename && strcmp(filename, cmd->containerName()) == 0)
return(i);
}
return(-1);

View File

@@ -461,7 +461,7 @@ SendMsgDialog::updateMsgHnd()
{
DtMailEnv error;
DtMail::Envelope * env;
int textLen;
int textLen = 0;
env = _msgHandle->getEnvelope(error);
storeHeaders();
@@ -472,9 +472,9 @@ SendMsgDialog::updateMsgHnd()
XtFree(widget_text);
widget_text = NULL;
}
else
textLen = strlen(widget_text);
else if(widget_text) {
textLen = strlen(widget_text);
}
// Even if textlen is 0 because user has cleared all previous text,
// need to setContents again to clear first BP. Otherwise, deleted
// text will show up.
@@ -3150,7 +3150,7 @@ SendMsgDialog::parseNplace(const char * path)
if (SafeRead(fd, _dead_letter_buf,
(unsigned int) buf.st_size) != buf.st_size) {
delete _dead_letter_buf;
delete [] _dead_letter_buf;
close(fd);
return;
}

View File

@@ -355,7 +355,7 @@ Sort::sortMessages(MsgScrollingList *displayList,
}
// Now cleanup.
delete messages;
delete [] messages;
}
//

View File

@@ -3054,11 +3054,10 @@ determine_exe_dir(
if (path_prefix != NULL)
{
char *abs_exe_dir = new char[MAXPATHLEN+1];
strcpy(abs_exe_dir, path_prefix);
if (strcmp(buf, ".") != 0)
{
strcat(abs_exe_dir, "/");
strcat(abs_exe_dir, buf);
if (strcmp(buf, ".") != 0) {
snprintf(abs_exe_dir, MAXPATHLEN+1, "%s/%s", path_prefix, buf);
} else {
snprintf(abs_exe_dir, MAXPATHLEN+1, "%s", path_prefix);
}
strcpy(buf, abs_exe_dir);
delete [] abs_exe_dir;