Fix svace issue 84/99484/1 accepted/tizen/common/20161124.170036 accepted/tizen/ivi/20161125.003439 accepted/tizen/mobile/20161125.003339 accepted/tizen/wearable/20161125.003419 submit/tizen/20161123.082735 submit/tizen/20161123.234422
authorkj7.sung <kj7.sung@samsung.com>
Wed, 23 Nov 2016 05:04:04 +0000 (14:04 +0900)
committerkj7.sung <kj7.sung@samsung.com>
Wed, 23 Nov 2016 05:04:04 +0000 (14:04 +0900)
Change-Id: I4593a860ce442bb7611428cccf322356b00156e5
Signed-off-by: kj7.sung <kj7.sung@samsung.com>
module/nps_module.c

index 145357b..7a35f42 100644 (file)
@@ -240,34 +240,43 @@ static int get_last_position(gpointer handle, LocationPosition **position, Locat
                        snprintf(location, sizeof(location), "%s", str);
                        free(str);
 
+                       index = 0;
                        last_location[index] = (char *)strtok_r(location, ";", &last);
-                       while (last_location[index++] != NULL) {
-                               if (index == MAX_NPS_LOC_ITEM)
+                       while (last_location[index] != NULL) {
+                               switch (index) {
+                               case 0:
+                                       latitude = strtod(last_location[index], NULL);
+                                       break;
+                               case 1:
+                                       longitude = strtod(last_location[index], NULL);
+                                       break;
+                               case 2:
+                                       altitude = strtod(last_location[index], NULL);
+                                       break;
+                               case 3:
+                                       speed = strtod(last_location[index], NULL);
+                                       break;
+                               case 4:
+                                       direction = strtod(last_location[index], NULL);
+                                       break;
+                               case 5:
+                                       hor_accuracy = strtod(last_location[index], NULL);
+                                       break;
+                               default:
                                        break;
+                               }
+                               if (++index == MAX_NPS_LOC_ITEM) break;
                                last_location[index] = (char *)strtok_r(NULL, ";", &last);
                        }
-
-                       if (index != MAX_NPS_LOC_ITEM) {
-                               MOD_NPS_LOGD("Error item index");
-                               return LOCATION_ERROR_NOT_AVAILABLE;
-                       }
-                       index = 0;
-                       latitude = strtod(last_location[index++], NULL);
-                       longitude = strtod(last_location[index++], NULL);
-                       altitude = strtod(last_location[index++], NULL);
-                       speed = strtod(last_location[index++], NULL);
-                       direction = strtod(last_location[index++], NULL);
-                       hor_accuracy = strtod(last_location[index], NULL);
                }
        }
 
-       level = LOCATION_ACCURACY_LEVEL_STREET;
-
        if (timestamp)
                status = LOCATION_STATUS_3D_FIX;
        else
                return LOCATION_ERROR_NOT_AVAILABLE;
 
+       level = LOCATION_ACCURACY_LEVEL_STREET;
        *position = location_position_new((guint) timestamp, latitude, longitude, altitude, status);
        *velocity = location_velocity_new((guint) timestamp, speed, direction, 0.0);
        *accuracy = location_accuracy_new(level, hor_accuracy, -1.0);