Fixing crash in OCFillRandomMem (#512)
[platform/upstream/iotivity.git] / resource / c_common / ocrandom / src / ocrandom.c
index 97fe7be..babf32b 100644 (file)
@@ -187,17 +187,18 @@ int8_t OCSeedRandom()
 
 void OCFillRandomMem(uint8_t * location, uint16_t len)
 {
+    int i, j, rand_idx;
+    i = len;
     if (!location)
     {
         return;
     }
-    for (; len--;)
+    for (; i--;)
     {
         *location++ = OCGetRandomByte();
     }
     uint8_t *temp = (char *) OICCalloc(len, sizeof(char));
     int *mask = (int *) OICCalloc(len, sizeof(int));
-    int i, j, rand_idx;
     for (i = 0; i < len; i++)
     {
         mask[i] = 0;