[IOT-2764] Fix issue in GetObserverUsingId() 99/22599/5
authorSushil Yadav <sushil.ky@samsung.com>
Tue, 26 Sep 2017 05:40:35 +0000 (11:10 +0530)
committerAshok Babu Channa <ashok.channa@samsung.com>
Thu, 12 Oct 2017 05:30:33 +0000 (05:30 +0000)
The GetObserverUsingId() function should not assumes that observeId > 0.
For presenceResource the observeId = 0 when it is added as observer in
OCStartPresence() calls AddObserver() for presenceResource.

Bug: https://jira.iotivity.org/browse/IOT-2764
Change-Id: I6dceba0e2e8415c8e9d6b42339f30612b626cb0b
Signed-off-by: Sushil Yadav <sushil.ky@samsung.com>
resource/csdk/stack/src/ocobserve.c

index 2949e00..3b6b9e1 100644 (file)
@@ -472,18 +472,19 @@ ResourceObserver* GetObserverUsingId (const OCObservationId observeId)
 {
     ResourceObserver *out = NULL;
 
-    if (observeId)
+    LL_FOREACH (g_serverObsList, out)
     {
-        LL_FOREACH (g_serverObsList, out)
+        if (out->observeId == observeId)
         {
-            if (out->observeId == observeId)
-            {
-                return out;
-            }
-            CheckTimedOutObserver(out);
+            return out;
         }
+        CheckTimedOutObserver(out);
+    }
+
+    if (!out)
+    {
+        OIC_LOG(INFO, TAG, "Observer node not found!!");
     }
-    OIC_LOG(INFO, TAG, "Observer node not found!!");
     return NULL;
 }