From b2562fdda825eaee1020bd39d04229e730274b3e Mon Sep 17 00:00:00 2001 From: Erich Keane Date: Fri, 31 Jul 2015 15:55:45 -0700 Subject: [PATCH] Fixed a few SonarQube identified issues JniListenerManager tried to modify its list inside of a for-loop, which causes undefined behavior. 2 spots where there was un-initialized variables. Change-Id: I5da2cd39cef1dadcd05c743d8fc5e0db0a8f2679 Signed-off-by: Erich Keane Reviewed-on: https://gerrit.iotivity.org/gerrit/2033 Reviewed-by: Tim Kourt Tested-by: jenkins-iotivity Reviewed-by: Jon A. Cruz --- android/android_api/base/jni/JniListenerManager.h | 15 ++++++++------- android/android_api/base/jni/JniOcPlatform.cpp | 2 +- resource/csdk/ocrandom/src/ocrandom.c | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/android/android_api/base/jni/JniListenerManager.h b/android/android_api/base/jni/JniListenerManager.h index 709328a..52eddc3 100644 --- a/android/android_api/base/jni/JniListenerManager.h +++ b/android/android_api/base/jni/JniListenerManager.h @@ -58,7 +58,9 @@ public: if (jgListener) { - m_listenerMap.insert(std::pair>(jgListener, std::pair(onEventListener, 1))); + m_listenerMap.insert( + std::pair>(jgListener, std::pair(onEventListener, 1))); } else { @@ -105,14 +107,13 @@ public: { m_mapMutex.lock(); - for (auto it = m_listenerMap.begin(); it != m_listenerMap.end(); ++it) + for (auto& pair : m_listenerMap) { - env->DeleteGlobalRef(it->first); - auto refPair = it->second; - T* listener = refPair.first; - delete listener; - m_listenerMap.erase(it); + env->DeleteGlobalRef(pair.first); + auto refPair = pair.second; + delete refPair.first; } + m_listenerMap.clear(); m_mapMutex.unlock(); } diff --git a/android/android_api/base/jni/JniOcPlatform.cpp b/android/android_api/base/jni/JniOcPlatform.cpp index c8a619e..3b67b6c 100644 --- a/android/android_api/base/jni/JniOcPlatform.cpp +++ b/android/android_api/base/jni/JniOcPlatform.cpp @@ -325,7 +325,7 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_configure dbfile = env->GetStringUTFChars(jDbPath, nullptr); JniOcSecurity::StoreDbPath(dbfile); } - uint16_t port; + uint16_t port = 0; if (jPort > 0) { port = static_cast(jPort); diff --git a/resource/csdk/ocrandom/src/ocrandom.c b/resource/csdk/ocrandom/src/ocrandom.c index dd03cd9..0d0f0c1 100644 --- a/resource/csdk/ocrandom/src/ocrandom.c +++ b/resource/csdk/ocrandom/src/ocrandom.c @@ -70,7 +70,7 @@ int8_t OCSeedRandom() { #if defined(__ANDROID__) || defined(__linux__) || defined(__APPLE__) int32_t fd = open("/dev/urandom", O_RDONLY); if (fd > 0) { - uint32_t randomSeed; + uint32_t randomSeed = 0; uint32_t totalRead = 0; //how many integers were read int32_t currentRead = 0; while (totalRead < sizeof(randomSeed)) { -- 2.7.4