diff options
author | 2014-12-11 14:24:03 -0800 | |
---|---|---|
committer | 2014-12-11 14:24:03 -0800 | |
commit | 475d817e0230342443203f3b9b3dfe2a45a71779 (patch) | |
tree | 74803f62785a268e477fb82f96f98fc7e65f1686 /src/core | |
parent | 129a55d2098fbb114fcb7e785b31ce270e9cfda0 (diff) |
Fixed analyzer issues and warnings (#993 and fixed #992)
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/basetypes/MCArray.h | 2 | ||||
-rw-r--r-- | src/core/basetypes/MCAssert.h | 2 | ||||
-rw-r--r-- | src/core/basetypes/MCHashMap.cpp | 3 | ||||
-rw-r--r-- | src/core/basetypes/MCIterator.h | 3 | ||||
-rw-r--r-- | src/core/basetypes/MCObject.cpp | 26 | ||||
-rw-r--r-- | src/core/basetypes/MCOperationQueue.cpp | 2 | ||||
-rw-r--r-- | src/core/basetypes/MCString.cpp | 1 | ||||
-rw-r--r-- | src/core/basetypes/MCUtils.h | 17 | ||||
-rw-r--r-- | src/core/imap/MCIMAPIdentity.cpp | 5 | ||||
-rw-r--r-- | src/core/imap/MCIMAPIdentity.h | 4 | ||||
-rwxr-xr-x | src/core/imap/MCIMAPSession.cpp | 20 | ||||
-rw-r--r-- | src/core/nntp/MCNNTPSession.cpp | 2 | ||||
-rw-r--r-- | src/core/smtp/MCSMTPSession.cpp | 4 | ||||
-rw-r--r-- | src/core/zip/MiniZip/unzip.c | 5 | ||||
-rw-r--r-- | src/core/zip/MiniZip/zip.c | 6 |
15 files changed, 70 insertions, 32 deletions
diff --git a/src/core/basetypes/MCArray.h b/src/core/basetypes/MCArray.h index 655eee5f..bed43fe5 100644 --- a/src/core/basetypes/MCArray.h +++ b/src/core/basetypes/MCArray.h @@ -25,7 +25,7 @@ namespace mailcore { virtual void removeObjectAtIndex(unsigned int idx); virtual void removeObject(Object * obj); virtual int indexOfObject(Object * obj); - virtual Object * objectAtIndex(unsigned int idx); + virtual Object * objectAtIndex(unsigned int idx) ATTRIBUTE_RETURNS_NONNULL; virtual void replaceObject(unsigned int idx, Object * obj); virtual void insertObject(unsigned int idx, Object * obj); virtual void removeAllObjects(); diff --git a/src/core/basetypes/MCAssert.h b/src/core/basetypes/MCAssert.h index 4022e285..7858693f 100644 --- a/src/core/basetypes/MCAssert.h +++ b/src/core/basetypes/MCAssert.h @@ -10,7 +10,7 @@ extern "C" { #endif MAILCORE_EXPORT - void MCAssertInternal(const char * filename, unsigned int line, int cond, const char * condString); + void MCAssertInternal(const char * filename, unsigned int line, int cond, const char * condString) CLANG_ANALYZER_NORETURN; #ifdef __cplusplus } #endif diff --git a/src/core/basetypes/MCHashMap.cpp b/src/core/basetypes/MCHashMap.cpp index 486707e9..c56277fc 100644 --- a/src/core/basetypes/MCHashMap.cpp +++ b/src/core/basetypes/MCHashMap.cpp @@ -31,7 +31,8 @@ namespace mailcore { void HashMap::init() { mCount = 0; - mCells = (void **) (HashMapCell **) calloc(CHASH_DEFAULTSIZE, sizeof(HashMapCell *)); + size_t hashMapCellSize = sizeof(HashMapCell *); + mCells = (void **) calloc(CHASH_DEFAULTSIZE, hashMapCellSize); mAllocated = CHASH_DEFAULTSIZE; } diff --git a/src/core/basetypes/MCIterator.h b/src/core/basetypes/MCIterator.h index e1f258d4..a3e5b1c1 100644 --- a/src/core/basetypes/MCIterator.h +++ b/src/core/basetypes/MCIterator.h @@ -14,6 +14,7 @@ #include <MailCore/MCHashMap.h> #include <MailCore/MCIndexSet.h> #include <MailCore/MCAutoreleasePool.h> +#include <MailCore/MCAssert.h> #include <string.h> #ifdef __cplusplus @@ -157,9 +158,11 @@ namespace mailcore { } if (keyp != NULL) { + MCAssert(iterator->keys != NULL); * keyp = iterator->keys->objectAtIndex(iterator->index); } if (valuep != NULL) { + MCAssert(iterator->values != NULL); * valuep = iterator->values->objectAtIndex(iterator->index); } iterator->index ++; diff --git a/src/core/basetypes/MCObject.cpp b/src/core/basetypes/MCObject.cpp index fbb7cb68..28fa3544 100644 --- a/src/core/basetypes/MCObject.cpp +++ b/src/core/basetypes/MCObject.cpp @@ -165,7 +165,9 @@ static void removeFromPerformHash(Object * obj, Object::Method method, void * co struct mainThreadCallKeyData keyData; Object * queueIdentifier = NULL; #if __APPLE__ - queueIdentifier = (String *) dispatch_queue_get_specific((dispatch_queue_t) targetDispatchQueue, "MCDispatchQueueID"); + if (targetDispatchQueue != NULL) { + queueIdentifier = (Object *) dispatch_queue_get_specific((dispatch_queue_t) targetDispatchQueue, "MCDispatchQueueID"); + } #endif memset(&keyData, 0, sizeof(keyData)); keyData.dispatchQueueIdentifier = queueIdentifier; @@ -194,10 +196,15 @@ static void addToPerformHash(Object * obj, Object::Method method, void * context struct mainThreadCallKeyData keyData; Object * queueIdentifier = NULL; #if __APPLE__ - queueIdentifier = (String *) dispatch_queue_get_specific((dispatch_queue_t) targetDispatchQueue, "MCDispatchQueueID"); - if (queueIdentifier == NULL) { - queueIdentifier = new Object(); - dispatch_queue_set_specific((dispatch_queue_t) targetDispatchQueue, "MCDispatchQueueID", queueIdentifier, queueIdentifierDestructor); + if (targetDispatchQueue == NULL) { + queueIdentifier = NULL; + } + else { + queueIdentifier = (Object *) dispatch_queue_get_specific((dispatch_queue_t) targetDispatchQueue, "MCDispatchQueueID"); + if (queueIdentifier == NULL) { + queueIdentifier = new Object(); + dispatch_queue_set_specific((dispatch_queue_t) targetDispatchQueue, "MCDispatchQueueID", queueIdentifier, queueIdentifierDestructor); + } } #endif memset(&keyData, 0, sizeof(keyData)); @@ -223,10 +230,11 @@ static void * getFromPerformHash(Object * obj, Object::Method method, void * con Object * queueIdentifier = NULL; #if __APPLE__ - MCAssert(targetDispatchQueue != NULL); - queueIdentifier = (String *) dispatch_queue_get_specific((dispatch_queue_t) targetDispatchQueue, "MCDispatchQueueID"); - if (queueIdentifier == NULL) - return NULL; + if (targetDispatchQueue != NULL) { + queueIdentifier = (Object *) dispatch_queue_get_specific((dispatch_queue_t) targetDispatchQueue, "MCDispatchQueueID"); + if (queueIdentifier == NULL) + return NULL; + } #endif memset(&keyData, 0, sizeof(keyData)); keyData.dispatchQueueIdentifier = queueIdentifier; diff --git a/src/core/basetypes/MCOperationQueue.cpp b/src/core/basetypes/MCOperationQueue.cpp index b9e8d779..bfe3a6fb 100644 --- a/src/core/basetypes/MCOperationQueue.cpp +++ b/src/core/basetypes/MCOperationQueue.cpp @@ -11,6 +11,7 @@ #include "MCLog.h" #include "MCAutoreleasePool.h" #include "MCMainThreadAndroid.h" +#include "MCAssert.h" using namespace mailcore; @@ -112,6 +113,7 @@ void OperationQueue::runOperations() break; } + MCAssert(op != NULL); performOnCallbackThread(op, (Object::Method) &OperationQueue::beforeMain, op, true); if (!op->isCancelled() || op->shouldRunWhenCancelled()) { diff --git a/src/core/basetypes/MCString.cpp b/src/core/basetypes/MCString.cpp index d1115c40..2239363b 100644 --- a/src/core/basetypes/MCString.cpp +++ b/src/core/basetypes/MCString.cpp @@ -939,6 +939,7 @@ void String::appendCharactersLength(const UChar * unicodeCharacters, unsigned in return; } allocate(mLength + length); + MCAssert(mUnicodeChars != NULL); memcpy(&mUnicodeChars[mLength], unicodeCharacters, length * sizeof(* mUnicodeChars)); mLength += length; mUnicodeChars[mLength] = 0; diff --git a/src/core/basetypes/MCUtils.h b/src/core/basetypes/MCUtils.h index 3892350f..eb4ef290 100644 --- a/src/core/basetypes/MCUtils.h +++ b/src/core/basetypes/MCUtils.h @@ -48,4 +48,21 @@ # define MAILCORE_EXPORT #endif +#ifdef __clang__ + +#if __has_feature(attribute_analyzer_noreturn) +#define CLANG_ANALYZER_NORETURN __attribute__((analyzer_noreturn)) +#else +#define CLANG_ANALYZER_NORETURN +#endif + +#define ATTRIBUTE_RETURNS_NONNULL __attribute__((returns_nonnull)) + +#else + +#define CLANG_ANALYZER_NORETURN +#define ATTRIBUTE_RETURNS_NONNULL + +#endif + #endif diff --git a/src/core/imap/MCIMAPIdentity.cpp b/src/core/imap/MCIMAPIdentity.cpp index 2e22d539..a94d01df 100644 --- a/src/core/imap/MCIMAPIdentity.cpp +++ b/src/core/imap/MCIMAPIdentity.cpp @@ -83,6 +83,11 @@ void IMAPIdentity::setInfoForKey(String * key, String * value) } } +void IMAPIdentity::removeAllInfos() +{ + mValues->removeAllObjects(); +} + Object * IMAPIdentity::copy() { return new IMAPIdentity(this); diff --git a/src/core/imap/MCIMAPIdentity.h b/src/core/imap/MCIMAPIdentity.h index 4f85744d..ee6b3c5e 100644 --- a/src/core/imap/MCIMAPIdentity.h +++ b/src/core/imap/MCIMAPIdentity.h @@ -21,7 +21,7 @@ namespace mailcore { IMAPIdentity(); virtual ~IMAPIdentity(); - + virtual void setVendor(String * vendor); virtual String * vendor(); @@ -30,6 +30,8 @@ namespace mailcore { virtual void setVersion(String * version); virtual String * version(); + + virtual void removeAllInfos(); virtual Array * allInfoKeys(); virtual String * infoForKey(String * key); diff --git a/src/core/imap/MCIMAPSession.cpp b/src/core/imap/MCIMAPSession.cpp index f286cc52..dcb82c63 100755 --- a/src/core/imap/MCIMAPSession.cpp +++ b/src/core/imap/MCIMAPSession.cpp @@ -1877,10 +1877,8 @@ HashMap * IMAPSession::fetchMessageNumberUIDMapping(String * folder, uint32_t fr } struct msg_att_handler_data { - IMAPSession * self; bool fetchByUID; Array * result; - String * folder; IMAPMessagesRequestKind requestKind; uint32_t mLastFetchedSequenceNumber; HashMap * mapping; @@ -1905,11 +1903,8 @@ static void msg_att_handler(struct mailimap_msg_att * msg_att, void * context) bool hasGmailMessageID; bool hasGmailThreadID; struct msg_att_handler_data * msg_att_context; - // struct - IMAPSession * self; bool fetchByUID; Array * result; - String * folder; IMAPMessagesRequestKind requestKind; uint32_t mLastFetchedSequenceNumber; HashMap * mapping; @@ -1922,12 +1917,9 @@ static void msg_att_handler(struct mailimap_msg_att * msg_att, void * context) uint32_t startUid; msg_att_context = (struct msg_att_handler_data *) context; - self = msg_att_context->self; fetchByUID = msg_att_context->fetchByUID; result = msg_att_context->result; - folder = msg_att_context->folder; requestKind = msg_att_context->requestKind; - mLastFetchedSequenceNumber = msg_att_context->mLastFetchedSequenceNumber; mapping = msg_att_context->mapping; needsHeader = msg_att_context->needsHeader; needsBody = msg_att_context->needsBody; @@ -2104,6 +2096,10 @@ static void msg_att_handler(struct mailimap_msg_att * msg_att, void * context) msg->release(); return; } + if (needsGmailLabels && !hasGmailLabels) { + msg->release(); + return; + } if (uid != 0) { msg->setUid(uid); } @@ -2280,10 +2276,8 @@ IMAPSyncResult * IMAPSession::fetchMessages(String * folder, IMAPMessagesRequest struct msg_att_handler_data msg_att_data; memset(&msg_att_data, 0, sizeof(msg_att_data)); - msg_att_data.self = this; msg_att_data.fetchByUID = fetchByUID; msg_att_data.result = messages; - msg_att_data.folder = folder; msg_att_data.requestKind = requestKind; msg_att_data.mLastFetchedSequenceNumber = mLastFetchedSequenceNumber; msg_att_data.mapping = mapping; @@ -2603,8 +2597,8 @@ Data * IMAPSession::fetchMessageAttachment(String * folder, bool identifier_is_u clist * sec_list; Array * partIDArray; int r; - char * text; - size_t text_length; + char * text = NULL; + size_t text_length = 0; Data * data; selectIfNeeded(folder, pError); @@ -2650,7 +2644,7 @@ Data * IMAPSession::fetchMessageAttachment(String * folder, bool identifier_is_u * pError = ErrorFetch; return NULL; } - + data = Data::dataWithBytes(text, (unsigned int) text_length); data = data->decodedDataUsingEncoding(encoding); diff --git a/src/core/nntp/MCNNTPSession.cpp b/src/core/nntp/MCNNTPSession.cpp index 44765a3e..f6427006 100644 --- a/src/core/nntp/MCNNTPSession.cpp +++ b/src/core/nntp/MCNNTPSession.cpp @@ -386,7 +386,7 @@ Array * NNTPSession::listDefaultNewsgroups(ErrorCode * pError) grp_info = (struct newsnntp_group_info *) clist_content(iter); - name = String::stringWithUTF8Characters(strdup(grp_info->grp_name)); + name = String::stringWithUTF8Characters(grp_info->grp_name); name->retain(); NNTPGroupInfo * info = new NNTPGroupInfo(); diff --git a/src/core/smtp/MCSMTPSession.cpp b/src/core/smtp/MCSMTPSession.cpp index ad8b19e0..eab05730 100644 --- a/src/core/smtp/MCSMTPSession.cpp +++ b/src/core/smtp/MCSMTPSession.cpp @@ -650,7 +650,7 @@ void SMTPSession::sendMessage(Address * from, Array * recipients, Data * message goto err; } else if (r == MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION) { - if (response->locationOfString(MCSTR("5.7.0")) != -1) { + if ((response != NULL) && (response->locationOfString(MCSTR("5.7.0")) != -1)) { * pError = ErrorSendMessageIllegalAttachment; } else { @@ -667,7 +667,7 @@ void SMTPSession::sendMessage(Address * from, Array * recipients, Data * message goto err; } else if (r != MAILSMTP_NO_ERROR) { - if ((responseCode == 550) && (response->hasPrefix(MCSTR("5.3.4")))) { + if ((responseCode == 550) && (response != NULL) && (response->hasPrefix(MCSTR("5.3.4")))) { * pError = ErrorNeedsConnectToWebmail; goto err; } diff --git a/src/core/zip/MiniZip/unzip.c b/src/core/zip/MiniZip/unzip.c index 7617f41f..2dd2907d 100644 --- a/src/core/zip/MiniZip/unzip.c +++ b/src/core/zip/MiniZip/unzip.c @@ -63,6 +63,7 @@ */ +#ifndef __clang_analyzer__ #include <stdio.h> #include <stdlib.h> @@ -1696,7 +1697,7 @@ extern int ZEXPORT unzReadCurrentFile (unzFile file, voidp buf, unsigned len) return UNZ_PARAMERROR; - if ((pfile_in_zip_read_info->read_buffer == NULL)) + if (pfile_in_zip_read_info->read_buffer == NULL) return UNZ_END_OF_LIST_OF_FILE; if (len==0) return 0; @@ -2123,3 +2124,5 @@ extern int ZEXPORT unzSetOffset (unzFile file, uLong pos) { return unzSetOffset64(file,pos); } + +#endif diff --git a/src/core/zip/MiniZip/zip.c b/src/core/zip/MiniZip/zip.c index 3c34fc8b..f8d21af5 100644 --- a/src/core/zip/MiniZip/zip.c +++ b/src/core/zip/MiniZip/zip.c @@ -21,6 +21,7 @@ */ +#ifndef __clang_analyzer__ #include <stdio.h> #include <stdlib.h> @@ -1114,9 +1115,9 @@ extern int ZEXPORT zipOpenNewFileInZip4_64 (zipFile file, const char* filename, zi->ci.flag = flagBase; if ((level==8) || (level==9)) zi->ci.flag |= 2; - if ((level==2)) + if (level==2) zi->ci.flag |= 4; - if ((level==1)) + if (level==1) zi->ci.flag |= 6; if (password != NULL) zi->ci.flag |= 1; @@ -2002,3 +2003,4 @@ extern int ZEXPORT zipRemoveExtraInfoBlock (char* pData, int* dataLen, short sHe return retVal; } +#endif |