From 475d817e0230342443203f3b9b3dfe2a45a71779 Mon Sep 17 00:00:00 2001 From: "Hoa V. DINH" Date: Thu, 11 Dec 2014 14:24:03 -0800 Subject: Fixed analyzer issues and warnings (#993 and fixed #992) --- build-mac/mailcore2.xcodeproj/project.pbxproj | 3 +-- src/async/imap/MCIMAPAsyncConnection.cpp | 7 +++++-- src/async/nntp/MCNNTPFetchOverviewOperation.cpp | 2 +- src/core/basetypes/MCArray.h | 2 +- src/core/basetypes/MCAssert.h | 2 +- src/core/basetypes/MCHashMap.cpp | 3 ++- src/core/basetypes/MCIterator.h | 3 +++ src/core/basetypes/MCObject.cpp | 26 ++++++++++++++++--------- src/core/basetypes/MCOperationQueue.cpp | 2 ++ src/core/basetypes/MCString.cpp | 1 + src/core/basetypes/MCUtils.h | 17 ++++++++++++++++ src/core/imap/MCIMAPIdentity.cpp | 5 +++++ src/core/imap/MCIMAPIdentity.h | 4 +++- src/core/imap/MCIMAPSession.cpp | 20 +++++++------------ src/core/nntp/MCNNTPSession.cpp | 2 +- src/core/smtp/MCSMTPSession.cpp | 4 ++-- src/core/zip/MiniZip/unzip.c | 5 ++++- src/core/zip/MiniZip/zip.c | 6 ++++-- src/objc/imap/MCOIMAPIdentity.h | 3 +++ src/objc/imap/MCOIMAPIdentity.mm | 5 +++++ unittest/unittest.cpp | 1 + 21 files changed, 86 insertions(+), 37 deletions(-) diff --git a/build-mac/mailcore2.xcodeproj/project.pbxproj b/build-mac/mailcore2.xcodeproj/project.pbxproj index 81c82fb0..ca40e92c 100755 --- a/build-mac/mailcore2.xcodeproj/project.pbxproj +++ b/build-mac/mailcore2.xcodeproj/project.pbxproj @@ -3700,7 +3700,6 @@ GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; - MACOSX_DEPLOYMENT_TARGET = 10.10; MTL_ENABLE_DEBUG_INFO = YES; OTHER_LDFLAGS = ( "-luchardet", @@ -3741,7 +3740,6 @@ GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; - MACOSX_DEPLOYMENT_TARGET = 10.10; MTL_ENABLE_DEBUG_INFO = NO; OTHER_LDFLAGS = ( "-luchardet", @@ -4128,6 +4126,7 @@ C600B6191A242C3F000728F1 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; C64EA531169E772200778456 /* Build configuration list for PBXProject "mailcore2" */ = { isa = XCConfigurationList; diff --git a/src/async/imap/MCIMAPAsyncConnection.cpp b/src/async/imap/MCIMAPAsyncConnection.cpp index b2fc24c3..c03422ff 100755 --- a/src/async/imap/MCIMAPAsyncConnection.cpp +++ b/src/async/imap/MCIMAPAsyncConnection.cpp @@ -239,8 +239,11 @@ IMAPNamespace * IMAPAsyncConnection::defaultNamespace() void IMAPAsyncConnection::setClientIdentity(IMAPIdentity * identity) { MC_SAFE_REPLACE_COPY(IMAPIdentity, mClientIdentity, identity); - mc_foreacharray(String, key, identity->allInfoKeys()) { - mSession->clientIdentity()->setInfoForKey(key, identity->infoForKey(key)); + mSession->clientIdentity()->removeAllInfos(); + if (identity != NULL) { + mc_foreacharray(String, key, identity->allInfoKeys()) { + mSession->clientIdentity()->setInfoForKey(key, identity->infoForKey(key)); + } } } diff --git a/src/async/nntp/MCNNTPFetchOverviewOperation.cpp b/src/async/nntp/MCNNTPFetchOverviewOperation.cpp index b05b29e6..749ea222 100644 --- a/src/async/nntp/MCNNTPFetchOverviewOperation.cpp +++ b/src/async/nntp/MCNNTPFetchOverviewOperation.cpp @@ -52,7 +52,7 @@ Array * NNTPFetchOverviewOperation::articles() { void NNTPFetchOverviewOperation::main() { - ErrorCode error; + ErrorCode error = ErrorNone; mArticles = Array::array(); for(unsigned int i = 0 ; i < mIndexes->rangesCount() ; i ++) { Range range = mIndexes->allRanges()[i]; 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 #include #include +#include #include #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 #include @@ -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 #include @@ -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 diff --git a/src/objc/imap/MCOIMAPIdentity.h b/src/objc/imap/MCOIMAPIdentity.h index 1690c0e3..69f18c96 100644 --- a/src/objc/imap/MCOIMAPIdentity.h +++ b/src/objc/imap/MCOIMAPIdentity.h @@ -37,6 +37,9 @@ /** Retrieve a custom field in the identity */ - (void) setInfo:(NSString *)value forKey:(NSString *)key; +/** Remove all info keys including vendor, name and version */ +- (void) removeAllInfos; + @end #endif diff --git a/src/objc/imap/MCOIMAPIdentity.mm b/src/objc/imap/MCOIMAPIdentity.mm index 0beb092b..08a73b2d 100644 --- a/src/objc/imap/MCOIMAPIdentity.mm +++ b/src/objc/imap/MCOIMAPIdentity.mm @@ -82,6 +82,11 @@ MCO_OBJC_SYNTHESIZE_STRING(setVersion, version) MCO_NATIVE_INSTANCE->setInfoForKey([key mco_mcString], [value mco_mcString]); } +- (void) removeAllInfos +{ + MCO_NATIVE_INSTANCE->removeAllInfos(); +} + + (MCOIMAPIdentity *) identityWithVendor:(NSString *)vendor name:(NSString *)name version:(NSString *)version diff --git a/unittest/unittest.cpp b/unittest/unittest.cpp index 8cf9908b..cdf02a2c 100644 --- a/unittest/unittest.cpp +++ b/unittest/unittest.cpp @@ -323,6 +323,7 @@ int main(int argc, char ** argv) AutoreleasePool * pool = new AutoreleasePool(); String * path = String::stringWithUTF8Characters(argv[1]); + MCAssert(path != NULL); printf("data path: %s\n", MCUTF8(path)); testMessageBuilder1(path->stringByAppendingPathComponent(MCSTR("builder"))); -- cgit v1.2.3