aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/basetypes
diff options
context:
space:
mode:
authorGravatar Hoa V. DINH <dinh.viet.hoa@gmail.com>2014-12-11 14:24:03 -0800
committerGravatar Hoa V. DINH <dinh.viet.hoa@gmail.com>2014-12-11 14:24:03 -0800
commit475d817e0230342443203f3b9b3dfe2a45a71779 (patch)
tree74803f62785a268e477fb82f96f98fc7e65f1686 /src/core/basetypes
parent129a55d2098fbb114fcb7e785b31ce270e9cfda0 (diff)
Fixed analyzer issues and warnings (#993 and fixed #992)
Diffstat (limited to 'src/core/basetypes')
-rw-r--r--src/core/basetypes/MCArray.h2
-rw-r--r--src/core/basetypes/MCAssert.h2
-rw-r--r--src/core/basetypes/MCHashMap.cpp3
-rw-r--r--src/core/basetypes/MCIterator.h3
-rw-r--r--src/core/basetypes/MCObject.cpp26
-rw-r--r--src/core/basetypes/MCOperationQueue.cpp2
-rw-r--r--src/core/basetypes/MCString.cpp1
-rw-r--r--src/core/basetypes/MCUtils.h17
8 files changed, 44 insertions, 12 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