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

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

@ -110,6 +110,7 @@ MainWindow::MainWindow( char *name, Boolean allowResize ) : UIComponent ( name )
_last_state = 0;
_flash_owin = 0;
_flash_iwin = 0;
_main = NULL;
memset(&_window_attributes, 0, sizeof(XWindowAttributes));
assert ( theApplication != NULL ); // Application object must exist

View file

@ -260,7 +260,7 @@ MenuBar::createPulldown (
}
XtManageChildren ( head_wl, num_wl );
delete head_wl;
delete [] head_wl;
return(pulldown);
}

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;

View file

@ -140,6 +140,7 @@ formatHeader (DtMailHeaderLine &info, enum DmxHeaderType htype)
break;
case NUMHDRTYPES:
default:
delete [] fbuf;
return "";
}
return (fbuf); //need to free this after using it

View file

@ -464,7 +464,7 @@ class DtMail {
void freerawlist(char **argv);
char *mt_value(char name[]);
char *expand(char *);
int getfolderdir(char *);
int getfolderdir(char *, size_t);
static int hash(char *name);
static void vfree(char *cp);

View file

@ -236,6 +236,8 @@ BufferMemory::iterate(Buffer::CallBack callback, ...)
// check for problems
if (ret) break;
}
va_end(va);
return (ret);
}

View file

@ -1986,16 +1986,16 @@ void DtMail::MailRc::add_alternates(char *name)
* Determine the current folder directory name.
*/
int
DtMail::MailRc::getfolderdir(char *name)
DtMail::MailRc::getfolderdir(char *name, size_t buffsize)
{
char *folder;
if ((folder = mt_value("folder")) == NOSTR)
return(-1);
if (*folder == '/')
strcpy(name, folder);
snprintf(name, buffsize, "%s", folder);
else
sprintf(name, "%s/%s", mt_value("HOME"), folder);
snprintf(name, buffsize, "%s/%s", mt_value("HOME"), folder);
return(0);
}
@ -2017,7 +2017,7 @@ DtMail::MailRc::expand(char *name)
struct stat sbuf;
char *retchr = NULL;
if (name[0] == '+' && getfolderdir(cmdbuf) >= 0) {
if (name[0] == '+' && getfolderdir(cmdbuf, LINESIZE) >= 0) {
sprintf(xname, "%s/%s", cmdbuf, name + 1);
str = expand(xname);
delete [] xname;

View file

@ -486,8 +486,9 @@ POP3Server::uidlist_read(DtVirtArray<char*> *uidlist)
while (NULL != fgets(uidliststr, DTMAS_POPBUFSIZE, fp))
if (sscanf(uidliststr, "%d %s", &curmsg, curuidstr) == 2)
uidlist->append(strdup(uidliststr));
fclose(fp);
}
fclose(fp);
}
void
@ -506,7 +507,6 @@ POP3Server::uidlist_write(DtVirtArray<char*> *uidlist)
uidliststr = (*uidlist)[i];
fprintf(fp, "%s\n", uidliststr);
}
fclose(fp);
}
fclose(fp);
}

View file

@ -267,24 +267,24 @@ MIMEBodyPart::getContentType(DtMailEnv &error, char **mime_type)
{
DtMailValueSeq value;
if (mime_type)
*mime_type = (char *)0;
if (mime_type) {
*mime_type = (char *)0;
if (_body_env)
_body_env->getHeader(error, "Content-Type", DTM_FALSE, value);
if (_body_env) {
_body_env->getHeader(error, "Content-Type", DTM_FALSE, value);
}
if (_body_env && !error.isSet())
{
// Handle "Content-Type: text" problem with /usr/lib/mail.local
if (strcasecmp(*(value[0]), "text")==0)
*mime_type = strdup("text/plain");
else
*mime_type = strdup(*(value[0]));
}
else
{
error.clear();
*mime_type = strdup("text/plain");
if (_body_env && !error.isSet()) {
// Handle "Content-Type: text" problem with /usr/lib/mail.local
if (strcasecmp(*(value[0]), "text")==0) {
*mime_type = strdup("text/plain");
} else {
*mime_type = strdup(*(value[0]));
}
} else {
error.clear();
*mime_type = strdup("text/plain");
}
}
}

View file

@ -168,7 +168,7 @@ extern "C" ssize_t pread(int, void *, size_t, off_t);
#endif
#define GET_DUMPFILE_NAME(dfn) \
sprintf(dfn, "%s/%s/dtmail.dump", getenv("HOME"), DtPERSONAL_TMP_DIRECTORY)
snprintf(dfn, sizeof(dfn), "%s/%s/dtmail.dump", getenv("HOME"), DtPERSONAL_TMP_DIRECTORY)
/*
* Local Data Definitions
@ -216,7 +216,7 @@ void HexDump(FILE *pfp, char *pmsg, unsigned char *pbufr, int plen, int plimit)
return;
if (pfp_r == (FILE*) NULL) {
char *dumpfilename = new char [MAXPATHLEN+1];
char dumpfilename[MAXPATHLEN+1];
_Xctimeparams ctime_buf;
GET_DUMPFILE_NAME(dumpfilename);
@ -225,7 +225,6 @@ void HexDump(FILE *pfp, char *pmsg, unsigned char *pbufr, int plen, int plimit)
memset((void*) &ctime_buf, 0, sizeof(_Xctimeparams));
fprintf(pfp_r, "--------------------- pid=%ld %s",
(long)getpid(), _XCtime(&clockTime, ctime_buf));
delete [] dumpfilename;
}
(void) fprintf(pfp_r, "--> %s (%d bytes at %p):\n", pmsg, plen, pbufr);
@ -2042,6 +2041,9 @@ RFCMailBox::mapFile(DtMailEnv & error,
}
error.setError(DTME_NoMemory);
delete map;
#if !defined(DO_ANONYMOUS_MAP)
SafeClose(fd);
#endif
return(-1);
}
@ -4506,7 +4508,7 @@ void
RFCMailBox::writeToDumpFile(const char *format, ...)
{
DtMailEnv error;
char *dumpfilename = new char[MAXPATHLEN+1];
char dumpfilename[MAXPATHLEN+1];
_Xctimeparams ctime_buf;
GET_DUMPFILE_NAME(dumpfilename);
@ -4524,8 +4526,7 @@ RFCMailBox::writeToDumpFile(const char *format, ...)
fprintf(df, "---------------------\n");
fprintf(df, "\n\n");
delete [] dumpfilename;
fclose(df);
}
@ -4558,7 +4559,7 @@ RFCMailBox::dumpMaps(const char *str)
DtMailEnv error;
off_t total_file_size = 0;
struct sigaction sig_act, old_sig_act;
char *dumpfilename = new char[MAXPATHLEN+1];
char dumpfilename[MAXPATHLEN+1];
GET_DUMPFILE_NAME(dumpfilename);
FILE *df = fopen(dumpfilename, "a");
@ -4567,7 +4568,6 @@ RFCMailBox::dumpMaps(const char *str)
error.logError(
DTM_FALSE,
"dumpMaps(): Cant open dump file %s\n", dumpfilename);
delete [] dumpfilename;
if (SafeFStat(_fd, &buf) < 0) {
fprintf(df, "dumpMaps(): fstat(%d) failed errno=%d\n", _fd, errno);

View file

@ -153,7 +153,7 @@ decode1522(const char * enc_start, const char * max_end, char **output, DtMail::
default:
// Invalid encoding. Assume a false match.
if (cs_name != NULL) free(cs_name);
free(cs_name);
return (enc_start);
}

View file

@ -346,24 +346,23 @@ V3BodyPart::getContentType(DtMailEnv &error, char **v3_type)
MutexLock dt_lib_lock(_DtMutex);
DtMailValueSeq value;
if (v3_type)
*v3_type = (char *)0;
if (v3_type) {
*v3_type = (char *)0;
_body_env->getHeader(error, "Content-Type", DTM_FALSE, value);
if (error.isNotSet())
*v3_type = strdup(*(value[0]));
else
{
error.clear();
value.clear();
_body_env->getHeader(error, "X-Sun-Data-Type", DTM_FALSE, value);
if (error.isNotSet())
*v3_type = strdup(*(value[0]));
else
{
error.clear();
*v3_type = strdup("text");
}
_body_env->getHeader(error, "Content-Type", DTM_FALSE, value);
if (error.isNotSet()) {
*v3_type = strdup(*(value[0]));
} else {
error.clear();
value.clear();
_body_env->getHeader(error, "X-Sun-Data-Type", DTM_FALSE, value);
if (error.isNotSet()) {
*v3_type = strdup(*(value[0]));
} else {
error.clear();
*v3_type = strdup("text");
}
}
}
}