From b5ead20a9b51f1c1b3f292a0931af043bcadc103 Mon Sep 17 00:00:00 2001 From: Jonathan Guthrie Date: Thu, 5 Dec 2013 20:02:01 -0600 Subject: [PATCH] Eliminate many of the warnings seen when the system is compiled with -Wall --- checkhandler.cpp | 2 ++ closehandler.cpp | 2 ++ datetime.cpp | 16 ++++++---- expungehandler.cpp | 6 ++++ imapsession.cpp | 2 ++ imapuser.cpp | 1 + listhandler.cpp | 4 +-- mailmessage.cpp | 14 ++++----- mailsearch.cpp | 7 +++-- mailstoreinvalid.cpp | 70 ++++++++++++++++++++++++++++++++++++++++++++ mailstorembox.cpp | 22 ++++++++++---- namespace.cpp | 4 ++- namespace.hpp | 2 +- sasl.cpp | 4 ++- selecthandler.cpp | 4 +++ 15 files changed, 134 insertions(+), 26 deletions(-) diff --git a/checkhandler.cpp b/checkhandler.cpp index 4b92c50..3282f90 100644 --- a/checkhandler.cpp +++ b/checkhandler.cpp @@ -22,6 +22,8 @@ ImapHandler *checkHandler(ImapSession *session, INPUT_DATA_STRUCT &input) { } IMAP_RESULTS CheckHandler::receiveData(INPUT_DATA_STRUCT &input) { + (void) input; + // Unlike NOOP, I always call mailboxFlushBuffers because that recalculates the the cached data. // That may be the only way to find out that the number of messages or the UIDNEXT value has // changed. diff --git a/closehandler.cpp b/closehandler.cpp index 2a55238..c0361af 100644 --- a/closehandler.cpp +++ b/closehandler.cpp @@ -22,6 +22,8 @@ ImapHandler *closeHandler(ImapSession *session, INPUT_DATA_STRUCT &input) { } IMAP_RESULTS CloseHandler::receiveData(INPUT_DATA_STRUCT &input) { + (void) input; + // If the mailbox is open, close it // In IMAP, deleted messages are always purged before a close IMAP_RESULTS result = IMAP_TRY_AGAIN; diff --git a/datetime.cpp b/datetime.cpp index bee19cb..abe5710 100644 --- a/datetime.cpp +++ b/datetime.cpp @@ -149,6 +149,8 @@ void DateTime::addDays(int days) { // DOW MMM DD hh:mm:ss YYYY // Note, no time zone. bool DateTime::parseCtime(const uint8_t *data, size_t dataLen, size_t &parsingAt) { + (void) dataLen; + m_valid = false; // Day of week // tuesday and thursday @@ -366,7 +368,7 @@ bool DateTime::parseCtime(const uint8_t *data, size_t dataLen, size_t &parsingAt if (1 == m_tm.tm_mon) { if ((29 < m_tm.tm_mday) || ((29 == m_tm.tm_mday) && - (0 != (m_tm.tm_year % 4)) || ((0 == m_tm.tm_year % 100) && (0 != m_tm.tm_year % 400)))) { + ((0 != (m_tm.tm_year % 4)) || ((0 == m_tm.tm_year % 100) && (0 != m_tm.tm_year % 400))))) { return false; } } @@ -514,7 +516,7 @@ bool DateTime::parseImap(const uint8_t *data, size_t dataLen, size_t &parsingAt) // If I'm looking at Feb 29, then it needs to be a leap year if ((1 == m_tm.tm_mon) && (29 == m_tm.tm_mday) && - (0 != (m_tm.tm_year % 4)) || ((0 == m_tm.tm_year % 100) && (0 != m_tm.tm_year % 400))) { + ((0 != (m_tm.tm_year % 4)) || ((0 == m_tm.tm_year % 100) && (0 != m_tm.tm_year % 400)))) { return false; } @@ -571,7 +573,7 @@ bool DateTime::parseImap(const uint8_t *data, size_t dataLen, size_t &parsingAt) // Use Zeller's Congruence to calculate the day of the week // See, for example http://en.wikipedia.org/wiki/Zeller's_congruence - int zMonth, zYear; + int zYear; int table[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4}; zYear = (m_tm.tm_mon < 2) ? m_tm.tm_year - 1 : m_tm.tm_year; m_tm.tm_wday = (zYear + zYear / 4 - zYear / 100 + zYear / 400 + table[m_tm.tm_mon] + m_tm.tm_mday) % 7; @@ -645,6 +647,8 @@ bool DateTime::parseImap(const uint8_t *data, size_t dataLen, size_t &parsingAt) * the obsolete fields are the same as the current fields. */ bool DateTime::parseRfc822(const uint8_t *data, size_t dataLen, size_t &parsingAt) { + (void) dataLen; + m_valid = false; // Day of week // tuesday and thursday @@ -849,7 +853,7 @@ bool DateTime::parseRfc822(const uint8_t *data, size_t dataLen, size_t &parsingA if (1 == m_tm.tm_mon) { if ((29 < m_tm.tm_mday) || ((29 == m_tm.tm_mday) && - (0 != (m_tm.tm_year % 4)) || ((0 == m_tm.tm_year % 100) && (0 != m_tm.tm_year % 400)))) { + ((0 != (m_tm.tm_year % 4)) || ((0 == m_tm.tm_year % 100) && (0 != m_tm.tm_year % 400))))) { return false; } } @@ -1054,6 +1058,8 @@ bool DateTime::parseRfc822(const uint8_t *data, size_t dataLen, size_t &parsingA */ bool DateTime::parseFromLine(const uint8_t *data, size_t dataLen, size_t &parsingAt) { + (void) dataLen; + m_valid = false; // It appears as if PostFix puts an extra space before the date @@ -1368,7 +1374,7 @@ bool DateTime::parseFromLine(const uint8_t *data, size_t dataLen, size_t &parsin if (1 == m_tm.tm_mon) { if ((29 < m_tm.tm_mday) || ((29 == m_tm.tm_mday) && - (0 != (m_tm.tm_year % 4)) || ((0 == m_tm.tm_year % 100) && (0 != m_tm.tm_year % 400)))) { + ((0 != (m_tm.tm_year % 4)) || ((0 == m_tm.tm_year % 100) && (0 != m_tm.tm_year % 400))))) { return false; } } diff --git a/expungehandler.cpp b/expungehandler.cpp index 1b83e66..edde897 100644 --- a/expungehandler.cpp +++ b/expungehandler.cpp @@ -22,6 +22,8 @@ ImapHandler *expungeHandler(ImapSession *session, INPUT_DATA_STRUCT &input) { } IMAP_RESULTS ExpungeHandler::receiveData(INPUT_DATA_STRUCT &input) { + (void) input; + IMAP_RESULTS result = IMAP_MBOX_ERROR; NUMBER_SET purgedMessages; @@ -34,6 +36,10 @@ IMAP_RESULTS ExpungeHandler::receiveData(INPUT_DATA_STRUCT &input) { case MailStore::CANNOT_COMPLETE_ACTION: result = IMAP_TRY_AGAIN; break; + + default: + result = IMAP_NO; + break; } return result; diff --git a/imapsession.cpp b/imapsession.cpp index ac12224..edb5734 100644 --- a/imapsession.cpp +++ b/imapsession.cpp @@ -953,6 +953,8 @@ void ImapSession::responseCode(const std::string &msg) { } void ImapSession::selectData(const std::string &mailbox, bool isReadWrite) { + (void) mailbox; + std::ostringstream ss; m_currentNextUid = m_store->serialNumber(); m_currentUidValidity = m_store->uidValidityNumber(); diff --git a/imapuser.cpp b/imapuser.cpp index 1e73a9d..598303e 100644 --- a/imapuser.cpp +++ b/imapuser.cpp @@ -19,6 +19,7 @@ #include "imapuser.hpp" ImapUser::ImapUser(const char *user, const ImapMaster *master) { + (void) master; m_name = new std::string(user); m_userFound = false; } diff --git a/listhandler.cpp b/listhandler.cpp index 666bd0f..d0d9e33 100644 --- a/listhandler.cpp +++ b/listhandler.cpp @@ -28,7 +28,7 @@ ImapHandler *listHandler(ImapSession *session, INPUT_DATA_STRUCT &input) { static std::string imapQuoteString(const std::string &to_be_quoted) { std::string result("\""); - for (int i=0; iarguments(); std::string mailbox = m_parseBuffer->arguments()+(strlen(m_parseBuffer->arguments())+1); diff --git a/mailmessage.cpp b/mailmessage.cpp index d950987..81dd97d 100644 --- a/mailmessage.cpp +++ b/mailmessage.cpp @@ -170,7 +170,7 @@ static MIME_MEDIA_TYPES GetMediaType(const insensitiveString &contentTypeLine) { if (0 < contentTypeLine.size()) { insensitiveString work = contentTypeLine; - int pos = work.find('/'); + size_t pos = work.find('/'); if (std::string::npos != pos) { int end = work.find_last_not_of(SPACE, pos-1); int begin = work.find_first_not_of(SPACE); @@ -204,10 +204,10 @@ std::string GetMediaBoundary(const insensitiveString &contentTypeLine) { std::string result; insensitiveString work = contentTypeLine; - int pos = work.find("boundary="); + size_t pos = work.find("boundary="); if (std::string::npos != pos) { - int end = work.find_last_not_of(SPACE); - int begin = work.find_first_not_of(SPACE, pos+9); + size_t end = work.find_last_not_of(SPACE); + size_t begin = work.find_first_not_of(SPACE, pos+9); result = contentTypeLine.substr(begin, end-begin+1).c_str(); pos = result.find(';'); @@ -231,11 +231,11 @@ bool MailMessage::processHeaderLine(const insensitiveString &line) { bool result = true; if (0 != line.size()) { - int colon = line.find(':'); + size_t colon = line.find(':'); if (std::string::npos != colon) { - int end = line.find_last_not_of(SPACE); - int begin = line.find_first_not_of(SPACE, colon+1); + size_t end = line.find_last_not_of(SPACE); + size_t begin = line.find_first_not_of(SPACE, colon+1); insensitiveString right; if (std::string::npos != begin) { right = line.substr(begin, end-begin+1); diff --git a/mailsearch.cpp b/mailsearch.cpp index 092f6ef..c6cd57d 100644 --- a/mailsearch.cpp +++ b/mailsearch.cpp @@ -361,7 +361,7 @@ static bool recursiveBodySearch(MESSAGE_BODY root, const MailSearch::TEXT_SEARCH } if (!result) { if (NULL != root.subparts) { - for (int i = 0; i < root.subparts->size(); i++) { + for (size_t i = 0; i < root.subparts->size(); i++) { result = recursiveBodySearch((*root.subparts)[i], target, bigBuffer); } } @@ -380,7 +380,7 @@ MailStore::MAIL_STORE_RESULT MailSearch::evaluate(MailStore *where) { } else { if ((0 != (m_includeMask | m_excludeMask)) || - (0 < m_smallestSize) || ((~0) > m_largestSize) || + (0 < m_smallestSize) || (LONG_MAX > m_largestSize) || (NULL != m_beginInternalDate) || (NULL != m_endInternalDate)) { if ((0 == (m_includeMask & m_excludeMask)) && (m_smallestSize <= m_largestSize) && @@ -466,6 +466,9 @@ MailStore::MAIL_STORE_RESULT MailSearch::evaluate(MailStore *where) { itIsIn = (std::string::npos != line.find(target)); } break; + + default: + break; } } diff --git a/mailstoreinvalid.cpp b/mailstoreinvalid.cpp index 60243f5..ae6095b 100644 --- a/mailstoreinvalid.cpp +++ b/mailstoreinvalid.cpp @@ -20,14 +20,19 @@ MailStoreInvalid::MailStoreInvalid(ImapSession *session) : MailStore(session) { } MailStore::MAIL_STORE_RESULT MailStoreInvalid::createMailbox(const std::string &FullName) { + (void) FullName; return GENERAL_FAILURE; } MailStore::MAIL_STORE_RESULT MailStoreInvalid::deleteMailbox(const std::string &FullName) { + (void) FullName; return GENERAL_FAILURE; } MailStore::MAIL_STORE_RESULT MailStoreInvalid::renameMailbox(const std::string &SourceName, const std::string &DestinationName) { + (void) SourceName; + (void) DestinationName; + return GENERAL_FAILURE; } @@ -36,22 +41,43 @@ MailStore::MAIL_STORE_RESULT MailStoreInvalid::mailboxClose() { } void MailStoreInvalid::mailboxList(const std::string &pattern, MAILBOX_LIST *result, bool listAll) { + (void) pattern; + (void) result; + (void) listAll; + // The nothing that MAILBOX_LIST starts as is is appropriate here. } MailStore::MAIL_STORE_RESULT MailStoreInvalid::subscribeMailbox(const std::string &MailboxName, bool isSubscribe) { + (void) MailboxName; + (void) isSubscribe; } MailStore::MAIL_STORE_RESULT MailStoreInvalid::addMessageToMailbox(const std::string &MailboxName, const uint8_t *data, size_t length, DateTime &createTime, uint32_t messageFlags, size_t *newUid ) { + (void) MailboxName; + (void) data; + (void) length; + (void) createTime; + (void) messageFlags; + (void) newUid; + return GENERAL_FAILURE; } MailStore::MAIL_STORE_RESULT MailStoreInvalid::appendDataToMessage(const std::string &MailboxName, size_t uid, const uint8_t *data, size_t length) { + (void) MailboxName; + (void) uid; + (void) data; + (void) length; + return GENERAL_FAILURE; } MailStore::MAIL_STORE_RESULT MailStoreInvalid::doneAppendingDataToMessage(const std::string &MailboxName, size_t uid) { + (void) MailboxName; + (void) uid; + return GENERAL_FAILURE; } @@ -66,20 +92,35 @@ unsigned MailStoreInvalid::uidValidityNumber() { } MailStore::MAIL_STORE_RESULT MailStoreInvalid::mailboxOpen(const std::string &MailboxName, bool readWrite) { + (void) MailboxName; + (void) readWrite; + return GENERAL_FAILURE; } MailStore::MAIL_STORE_RESULT MailStoreInvalid::listDeletedMessages(NUMBER_SET *nowGone) { + (void) nowGone; + return GENERAL_FAILURE; } MailStore::MAIL_STORE_RESULT MailStoreInvalid::expungeThisUid(unsigned long uid) { + (void) uid; + return GENERAL_FAILURE; } MailStore::MAIL_STORE_RESULT MailStoreInvalid::getMailboxCounts(const std::string &MailboxName, uint32_t which, unsigned &messageCount, unsigned &recentCount, unsigned &uidNext, unsigned &uidValidity, unsigned &firstUnseen) { + (void) MailboxName; + (void) which; + (void) messageCount; + (void) recentCount; + (void) uidNext; + (void) uidValidity; + (void) firstUnseen; + return GENERAL_FAILURE; } @@ -96,12 +137,18 @@ unsigned MailStoreInvalid::mailboxFirstUnseen() { } const DateTime &MailStoreInvalid::messageInternalDate(const unsigned long uid) { + (void) uid; // SYZYGY -- I need something like a void cast to DateTime that returns an error static DateTime now; return now; } MailStore::MAIL_STORE_RESULT MailStoreInvalid::messageUpdateFlags(unsigned long uid, uint32_t andMask, uint32_t orMask, uint32_t &flags) { + (void) uid; + (void) andMask; + (void) orMask; + (void) flags; + return GENERAL_FAILURE; } @@ -114,6 +161,8 @@ MailStore::MAIL_STORE_RESULT MailStoreInvalid::mailboxFlushBuffers(void) { } MailStore::MAIL_STORE_RESULT MailStoreInvalid::mailboxUpdateStats(NUMBER_SET *nowGone) { + (void) nowGone; + return GENERAL_FAILURE; } @@ -122,24 +171,38 @@ MailStoreInvalid::~MailStoreInvalid() { MailStore::MAIL_STORE_RESULT MailStoreInvalid::deleteMessage(const std::string &MailboxName, unsigned long uid) { + (void) MailboxName; + (void) uid; + return GENERAL_FAILURE; } MailMessage::MAIL_MESSAGE_RESULT MailStoreInvalid::messageData(MailMessage **message, unsigned long uid) { + (void) message; + (void) uid; + *message = NULL; return MailMessage::MESSAGE_DOESNT_EXIST; } MailStore::MAIL_STORE_RESULT MailStoreInvalid::openMessageFile(unsigned long uid) { + (void) uid; + return MailStore::GENERAL_FAILURE; } size_t MailStoreInvalid::bufferLength(unsigned long uid) { + (void) uid; + return 0; } size_t MailStoreInvalid::readMessage(char *buff, size_t offset, size_t length) { + (void) buff; + (void) offset; + (void) length; + return 0; } @@ -147,6 +210,13 @@ void MailStoreInvalid::closeMessageFile(void) { } const SEARCH_RESULT *MailStoreInvalid::searchMetaData(uint32_t xorMask, uint32_t andMask, size_t smallestSize, size_t largestSize, DateTime *beginInternalDate, DateTime *endInternalDate) { + (void) xorMask; + (void) andMask; + (void) smallestSize; + (void) largestSize; + (void) beginInternalDate; + (void) endInternalDate; + return NULL; } diff --git a/mailstorembox.cpp b/mailstorembox.cpp index 343c0a7..bf95ad4 100644 --- a/mailstorembox.cpp +++ b/mailstorembox.cpp @@ -78,11 +78,11 @@ static int writeMailboxMetadataFile(const char *filename, const char *fqdn, uid_ strftime(timestring, 1023, "%c", tm_now); outFile << "From MAILER-DAEMON " << timestring << std::endl; strftime(timestring, 1023, "%d %b %Y %X ", tm_now); - sprintf(tz_string, "% 03d%02d", zone_east / 60, zone_east % 60); + sprintf(tz_string, "% 03ld%02ld", zone_east / 60, zone_east % 60); outFile << "Date: " << timestring << tz_string << std::endl; outFile << "From: Mail Daemon " << std::endl; outFile << "Subject: DO NOT DELETE THIS MESSAGE -- IT CONTAINS INTERNAL FOLDER DATA" << std::endl; - sprintf(timestring, "%010u %010u", now, 0); + sprintf(timestring, "%010ld %010u", now, 0); outFile << "X-IMAP: " << timestring << std::endl; outFile << "Status: RO" << std::endl << std::endl; outFile << "This message contains metadata for this mail box and is not a real" << std::endl; @@ -222,7 +222,6 @@ MailStore::MAIL_STORE_RESULT MailStoreMbox::deleteMailbox(const std::string &Ful struct stat sb; std::string fullPath = *m_homeDirectory; - bool isDirectory = MailboxName.at(MailboxName.size()-1) == '/'; while ('/' == MailboxName.at(MailboxName.size()-1)) { MailboxName.erase(MailboxName.size()-1); @@ -395,7 +394,7 @@ void MailStoreMbox::addDataToMessageFile(const uint8_t *data, size_t length) { uid_t savedUserId = geteuid(); seteuid(m_session->user()->uid()); - for (int i=0; iuser()->uid()); m_outFile->write("\n", 1); @@ -710,7 +715,7 @@ bool MailStoreMbox::parseMessage(std::ifstream &inFile, bool firstMessage, bool messageMetaData.start = inFile.tellg(); getline(inFile, line); // Parse the "From " line for the internal date - int pos = line.find_first_of(' '); + size_t pos = line.find_first_of(' '); if (std::string::npos != pos) { pos = line.find_first_of(' ', pos+1); if (std::string::npos != pos) { @@ -841,6 +846,8 @@ bool MailStoreMbox::parseMessage(std::ifstream &inFile, bool firstMessage, bool // the results of that parsing for things like message sequence numbers, UID's, and offsets in the // file MailStore::MAIL_STORE_RESULT MailStoreMbox::mailboxOpen(const std::string &FullName, bool readWrite) { + (void) readWrite; + std::string MailboxName = FullName; std::string fullPath; MailStore::MAIL_STORE_RESULT result = MailStore::SUCCESS; @@ -1007,6 +1014,8 @@ MailStore::MAIL_STORE_RESULT MailStoreMbox::expungeThisUid(unsigned long uid) { MailStore::MAIL_STORE_RESULT MailStoreMbox::getMailboxCounts(const std::string &FullName, uint32_t which, unsigned &messageCount, unsigned &recentCount, unsigned &uidLast, unsigned &uidValidity, unsigned &firstUnseen) { + (void) which; + std::string MailboxName = FullName; std::string fullPath; MailStore::MAIL_STORE_RESULT result = MailStore::SUCCESS; @@ -1127,6 +1136,7 @@ MailStore::MAIL_STORE_RESULT MailStoreMbox::messageUpdateFlags(unsigned long uid std::string MailStoreMbox::mailboxUserPath() const { // SYZYGY -- what is this for? + return ""; } @@ -1189,7 +1199,7 @@ MailStore::MAIL_STORE_RESULT MailStoreMbox::mailboxFlushBuffers(void) { updateFile.clear(); buff1.count = updateFile.gcount(); bool notDone = true; - int messageIndex; + size_t messageIndex; unsigned parseState = 0; lastGetPos = updateFile.tellg(); bool isXheader; diff --git a/namespace.cpp b/namespace.cpp index a27a1a4..3986bf0 100644 --- a/namespace.cpp +++ b/namespace.cpp @@ -243,7 +243,7 @@ unsigned Namespace::uidValidityNumber() { } // This needs to be called ONLY when the m_selectedMailbox->mutex has been locked -bool Namespace::addSession(int refCount, expunged_message_t &message) { +bool Namespace::addSession(size_t refCount, expunged_message_t &message) { bool result = false; SessionList::iterator i = std::find(message.expungedSessions.begin(), message.expungedSessions.end(), m_session); if (message.expungedSessions.end() == i) { @@ -466,6 +466,7 @@ NUMBER_LIST Namespace::mailboxUidToMsn(const NUMBER_LIST &uids) { for (NUMBER_LIST::const_iterator i=uids.begin(); i!=uids.end(); ++i) { result.push_back(mailboxUidToMsn(*i)); } + return result; } unsigned long Namespace::mailboxUidToMsn(unsigned long uid) { @@ -527,6 +528,7 @@ MailStore::MAIL_STORE_RESULT Namespace::mailboxUpdateStatsInternal(NUMBER_SET *n nowGone->insert(nowGone->begin(), i->first); } } + return result; } MailStore::MAIL_STORE_RESULT Namespace::mailboxUpdateStats(NUMBER_SET *nowGone) { diff --git a/namespace.hpp b/namespace.hpp index 27ff7e1..c6805bc 100644 --- a/namespace.hpp +++ b/namespace.hpp @@ -142,7 +142,7 @@ class Namespace : public MailStore { MailStore *m_defaultNamespace; char m_defaultSeparator; void removeUid(unsigned long uid); - bool addSession(int refCount, expunged_message_t &message); + bool addSession(size_t refCount, expunged_message_t &message); unsigned m_mailboxMessageCount; void dump_message_session_info(const char *s, ExpungedMessageMap &m); MailStore::MAIL_STORE_RESULT mailboxUpdateStatsInternal(NUMBER_SET *uidsToBeExpunged); diff --git a/sasl.cpp b/sasl.cpp index 575cbb8..94f1493 100644 --- a/sasl.cpp +++ b/sasl.cpp @@ -35,7 +35,7 @@ std::string qstring(std::string &source) { /* It looks like a quoted string */ bool notdone = true; bool escape_flag = false; - int pos = 1; + size_t pos = 1; do { // std::cout << "pos = " << pos << "\n"; pos = (int)source.find_first_of("\"\\", pos); @@ -139,6 +139,8 @@ void SaslAnonymous::sendChallenge(char *challenge_buff) { } Sasl::status SaslAnonymous::receiveResponse(const std::string &csLine2) { + (void) csLine2; + // RFC 2245 says that the response is optional, but that it can contain // tracking stuff. I just ignore it until I have a use for it. m_authorizationEntity = ""; diff --git a/selecthandler.cpp b/selecthandler.cpp index 8361002..eed8a1c 100644 --- a/selecthandler.cpp +++ b/selecthandler.cpp @@ -56,6 +56,10 @@ IMAP_RESULTS SelectHandler::execute(void) { case MailStore::CANNOT_COMPLETE_ACTION: result = IMAP_TRY_AGAIN; break; + + default: + result = IMAP_NO; + break; } }