Fix warnings about diff and base possibly not initialized
authorThiago Macieira <thiago.macieira@intel.com>
Fri, 5 Sep 2014 01:00:53 +0000 (18:00 -0700)
committerErich Keane <erich.keane@intel.com>
Thu, 11 Sep 2014 17:56:04 +0000 (10:56 -0700)
This is a bogus warning by GCC, but it's easy to fix by having an "else"
case with no extra conditions.

Change-Id: I0f99527065138ff96c0613a57b0462613139900c
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
csdk/ocrandom/src/ocrandom.c

index 836887d..8c2d0a4 100644 (file)
@@ -120,14 +120,14 @@ uint32_t OCGetRandomRange(uint32_t firstBound, uint32_t secondBound){
     uint32_t base;
     uint32_t diff;
     uint32_t result;
-    if(firstBound == secondBound){
-        return secondBound;
-    }else if(firstBound > secondBound){
+    if(firstBound > secondBound){
         base = secondBound;
         diff = firstBound - secondBound;
     }else if(firstBound < secondBound){
         base = firstBound;
         diff = secondBound - firstBound;
+    }else{
+        return secondBound;
     }
     result = ((float)OCGetRandom()/((float)(0xFFFFFFFF))*(float)diff) + (float) base;
     return result;