From 2b55e431d9b83191e192a0e64e3a5cb60b13f8b6 Mon Sep 17 00:00:00 2001 From: chanywa Date: Tue, 8 Mar 2016 18:18:07 +0900 Subject: [PATCH] Fixed svace defects Change-Id: I7822d9539d477ece190b2dc63b31751f741439e9 --- src/mapquest/mapquest_geocode.c | 15 +++++++------- src/mapquest/mapquest_jsonparser.c | 21 ++++++++++--------- src/mapquest/mapquest_place.c | 8 ++++---- src/mapquest/mapquest_revgeocode.c | 5 +++-- src/mapquest/mapquest_route.c | 41 +++++++++++++++++++------------------ src/mapquest/mapquest_util.h | 3 +++ src/mapquest_plugin.c | 42 +++++++++++++++++++------------------- 7 files changed, 71 insertions(+), 64 deletions(-) diff --git a/src/mapquest/mapquest_geocode.c b/src/mapquest/mapquest_geocode.c index 553dce2..1349b10 100644 --- a/src/mapquest/mapquest_geocode.c +++ b/src/mapquest/mapquest_geocode.c @@ -23,6 +23,7 @@ #include "mapquest_debug.h" #include "mapquest_queue.h" #include "mapquest_restcurl.h" +#include "mapquest_util.h" #define GEOCODE_URL "https://open.mapquestapi.com/geocoding/v1/address?key=%s&inFormat=kvp&outFormat=json" @@ -36,16 +37,16 @@ int query_geocode_within_bounds(gchar *maps_key, char *address, coords_s top_lef else snprintf(tmpStr, sizeof(tmpStr), GEOCODE_URL, "null"); - strcpy(url, tmpStr); + STRCPY(url, tmpStr); snprintf(tmpStr, sizeof(tmpStr), "&boundingBox=%f,%f,%f,%f", top_left.latitude, top_left.longitude, bottom_right.latitude, bottom_right.longitude); - strcat(url, tmpStr); + STRCAT(url, tmpStr); snprintf(tmpStr, sizeof(tmpStr), "&maxResults=%d", num_results); - strcat(url, tmpStr); + STRCAT(url, tmpStr); snprintf(tmpStr, sizeof(tmpStr), "&location=%s", address); - strcat(url, tmpStr); + STRCAT(url, tmpStr); add_handle(url, REQ_TYPE_GEOCODE, user_data); @@ -63,13 +64,13 @@ int query_geocode(gchar *maps_key, char *address, int num_results, gpointer user else snprintf(tmpStr, sizeof(tmpStr), GEOCODE_URL, "null"); - strcpy(url, tmpStr); + STRCPY(url, tmpStr); snprintf(tmpStr, sizeof(tmpStr), "&maxResults=%d", num_results); - strcat(url, tmpStr); + STRCAT(url, tmpStr); snprintf(tmpStr, sizeof(tmpStr), "&location=%s", address); - strcat(url, tmpStr); + STRCAT(url, tmpStr); add_handle(url, REQ_TYPE_GEOCODE, user_data); diff --git a/src/mapquest/mapquest_jsonparser.c b/src/mapquest/mapquest_jsonparser.c index e549a5c..eff18bf 100644 --- a/src/mapquest/mapquest_jsonparser.c +++ b/src/mapquest/mapquest_jsonparser.c @@ -19,6 +19,7 @@ #include "mapquest_jsonparser.h" #include "mapquest_queue.h" #include "mapquest_debug.h" +#include "mapquest_util.h" #define ROUTE_UNIT_CONVERSION_MILE_TO_M(x) (1609.34 * (x)) #define ROUTE_UNIT_CONVERSION_MILE_TO_KM(x) (1.60934 * (x)) @@ -300,7 +301,7 @@ static void __parse_revgeocode_address(JsonNode *node, mapquest_address_resp_s * /* Street Address */ if (streetAddr != NULL) { (*respAddr)->street_add = (gchar *)g_malloc(strlen((char *)streetAddr) + 1); - strcpy((*respAddr)->street_add, (char *) streetAddr); + STRCPY((*respAddr)->street_add, (char *) streetAddr); } else { MAP_DEBUG("street is NULL"); (*respAddr)->street_add = NULL; @@ -309,7 +310,7 @@ static void __parse_revgeocode_address(JsonNode *node, mapquest_address_resp_s * /* Neighbourhood */ if (neighbourhood != NULL) { (*respAddr)->neighbourhood = (gchar *)g_malloc(strlen((char *)neighbourhood) + 1); - strcpy((*respAddr)->neighbourhood, (char *) neighbourhood); + STRCPY((*respAddr)->neighbourhood, (char *) neighbourhood); } else { MAP_DEBUG("neighbourhood is NULL"); (*respAddr)->neighbourhood = NULL; @@ -318,7 +319,7 @@ static void __parse_revgeocode_address(JsonNode *node, mapquest_address_resp_s * /* City */ if (city != NULL) { (*respAddr)->city = (gchar *)g_malloc(strlen((char *)city) + 1); - strcpy((*respAddr)->city, (char *) city); + STRCPY((*respAddr)->city, (char *) city); } else { MAP_DEBUG("city is NULL"); (*respAddr)->city = NULL; @@ -327,7 +328,7 @@ static void __parse_revgeocode_address(JsonNode *node, mapquest_address_resp_s * /* County */ if (county != NULL) { (*respAddr)->county = (gchar *)g_malloc(strlen((char *)county) + 1); - strcpy((*respAddr)->county, (char *) county); + STRCPY((*respAddr)->county, (char *) county); } else { MAP_DEBUG("county is NULL"); (*respAddr)->county = NULL; @@ -336,7 +337,7 @@ static void __parse_revgeocode_address(JsonNode *node, mapquest_address_resp_s * /* State */ if (state != NULL) { (*respAddr)->state = (gchar *)g_malloc(strlen((char *)state) + 1); - strcpy((*respAddr)->state, (char *) state); + STRCPY((*respAddr)->state, (char *) state); } else { MAP_DEBUG("state is NULL"); (*respAddr)->state = NULL; @@ -345,7 +346,7 @@ static void __parse_revgeocode_address(JsonNode *node, mapquest_address_resp_s * /* Country */ if (country != NULL) { (*respAddr)->country = (gchar *)g_malloc(strlen((char *)country) + 1); - strcpy((*respAddr)->country, (char *) country); + STRCPY((*respAddr)->country, (char *) country); } else { MAP_DEBUG("country is NULL"); (*respAddr)->country = NULL; @@ -358,7 +359,7 @@ static void __parse_revgeocode_address(JsonNode *node, mapquest_address_resp_s * /* Postal Code */ if (postalCode != NULL) { (*respAddr)->postal_code = (gchar *)g_malloc(strlen((char *)postalCode) + 1); - strcpy((*respAddr)->postal_code, (char *) postalCode); + STRCPY((*respAddr)->postal_code, (char *) postalCode); } else { MAP_DEBUG("postal_code is NULL"); (*respAddr)->postal_code = NULL; @@ -651,7 +652,7 @@ static void __maneuver_foreach(JsonObject *object, const gchar *member_name, Jso int length = json_array_get_length(streetsArray); char street_name[512]; - strcpy(street_name, ""); + STRCPY(street_name, ""); int index = 0; for (index = 0; index < length; index++) { char *name = (char *) json_array_get_string_element(streetsArray, index); @@ -659,7 +660,7 @@ static void __maneuver_foreach(JsonObject *object, const gchar *member_name, Jso if (index == 0) { strncpy(street_name, name, sizeof(street_name)-1); } else { - strcat(street_name, "/"); + STRCAT(street_name, "/"); strncat(street_name, name, sizeof(street_name)-strlen(street_name)-1); } } @@ -668,7 +669,7 @@ static void __maneuver_foreach(JsonObject *object, const gchar *member_name, Jso if (strlen(street_name) > 0) { (*maneuver)->street_name = (gchar *)g_malloc0((strlen((char *)street_name)) + 1); if ((*maneuver)->street_name) - strcpy((*maneuver)->street_name, (char *) street_name); + STRCPY((*maneuver)->street_name, (char *) street_name); } else { (*maneuver)->street_name = NULL; } diff --git a/src/mapquest/mapquest_place.c b/src/mapquest/mapquest_place.c index 52a05bc..4a89ee4 100644 --- a/src/mapquest/mapquest_place.c +++ b/src/mapquest/mapquest_place.c @@ -33,7 +33,7 @@ int query_places(gchar *maps_key, gchar *search_str, mapquest_boundary_s *bounda char url[1024]; char tmpStr[512]; - strcpy(url, PLACES_URL); + STRCPY(url, PLACES_URL); if (search_str != NULL) { snprintf(tmpStr, sizeof(tmpStr), "&q=%s", search_str); @@ -71,14 +71,14 @@ int query_places(gchar *maps_key, gchar *search_str, mapquest_boundary_s *bounda } } - strcat(url, "&bounded=1"); + STRCAT(url, "&bounded=1"); } - strcat(url, "&addressdetails=1"); + STRCAT(url, "&addressdetails=1"); if (num_res > 0) { snprintf(tmpStr, sizeof(tmpStr), "&limit=%d", num_res); - strcat(url, tmpStr); + STRCAT(url, tmpStr); } add_handle(url, REQ_TYPE_PLACES, user_data); diff --git a/src/mapquest/mapquest_revgeocode.c b/src/mapquest/mapquest_revgeocode.c index 246bee6..146ff23 100644 --- a/src/mapquest/mapquest_revgeocode.c +++ b/src/mapquest/mapquest_revgeocode.c @@ -23,6 +23,7 @@ #include "mapquest_debug.h" #include "mapquest_queue.h" #include "mapquest_restcurl.h" +#include "mapquest_util.h" #define REVERSE_GEOCODE_URL "https://open.mapquestapi.com/geocoding/v1/reverse?key=%s&outFormat=json" @@ -36,10 +37,10 @@ int query_revgeocode(gchar *maps_key, gdouble latitude, gdouble longitude, gpoin else snprintf(tmpStr, sizeof(tmpStr), REVERSE_GEOCODE_URL, "null"); - strcpy(url, tmpStr); + STRCPY(url, tmpStr); snprintf(tmpStr, sizeof(tmpStr), "&location=%f,%f", latitude, longitude); - strcat(url, tmpStr); + STRCAT(url, tmpStr); add_handle(url, REQ_TYPE_REVGEOCODE, user_data); diff --git a/src/mapquest/mapquest_route.c b/src/mapquest/mapquest_route.c index a4ec225..d9f3c93 100644 --- a/src/mapquest/mapquest_route.c +++ b/src/mapquest/mapquest_route.c @@ -23,12 +23,13 @@ #include "mapquest_debug.h" #include "mapquest_queue.h" #include "mapquest_restcurl.h" +#include "mapquest_util.h" #define ROUTE_URL "https://open.mapquestapi.com/directions/v2/route?key=%s&ambiguities=ignore&outFormat=json&shapeFormat=raw&generalize=0" int query_route(gchar *maps_key, coords_s startPoint, coords_s endPoint, route_type type, route_feature_avoids avoids, route_driving_style style, GList *waypoints, gpointer user_data) { - char url[1024]; + char url[1024] = ""; char tmpStr[512]; if (maps_key != NULL) @@ -36,40 +37,40 @@ int query_route(gchar *maps_key, coords_s startPoint, coords_s endPoint, route_t else snprintf(tmpStr, sizeof(tmpStr), ROUTE_URL, "null"); - strcpy(url, tmpStr); + STRCPY(url, tmpStr); - strcat(url, "&unit=m"); /* Keeping default as miles and conversion will be done later */ + STRCAT(url, "&unit=m"); /* Keeping default as miles and conversion will be done later */ if (type == ROUTE_TYPE_FASTEST) - strcat(url, "&routeType=fastest"); + STRCAT(url, "&routeType=fastest"); else if (type == ROUTE_TYPE_SHORTEST) - strcat(url, "&routeType=shortest"); + STRCAT(url, "&routeType=shortest"); else if (type == ROUTE_TYPE_PEDESTRIAN) - strcat(url, "&routeType=pedestrian"); + STRCAT(url, "&routeType=pedestrian"); else if (type == ROUTE_TYPE_MULTIMODAL) - strcat(url, "&routeType=multimodal"); + STRCAT(url, "&routeType=multimodal"); else if (type == ROUTE_TYPE_BICYCLE) - strcat(url, "&routeType=bicycle"); + STRCAT(url, "&routeType=bicycle"); if (avoids == ROUTE_AVOID_LIMITED_ACCESS) - strcat(url, "&avoids=Limited Access"); + STRCAT(url, "&avoids=Limited Access"); else if (avoids == ROUTE_AVOID_TOLL_ROAD) - strcat(url, "&avoids=Tollroad"); + STRCAT(url, "&avoids=Tollroad"); else if (avoids == ROUTE_AVOID_FERRY) - strcat(url, "&avoids=Ferry"); + STRCAT(url, "&avoids=Ferry"); else if (avoids == ROUTE_AVOID_UNPAVED) - strcat(url, "&avoids=Unpaved"); + STRCAT(url, "&avoids=Unpaved"); else if (avoids == ROUTE_AVOID_SEASONAL_CLOSURE) - strcat(url, "&avoids=Approximate Seasonal Closure"); + STRCAT(url, "&avoids=Approximate Seasonal Closure"); else if (avoids == ROUTE_AVOID_COUNTRY_BORDER_CROSSING) - strcat(url, "&avoids=Country border crossing"); + STRCAT(url, "&avoids=Country border crossing"); if (style == DRIVING_STYLE_NORMAL) - strcat(url, "&drivingStyle=2"); + STRCAT(url, "&drivingStyle=2"); else if (style == DRIVING_STYLE_CAUTIOUS) - strcat(url, "&drivingStyle=1"); + STRCAT(url, "&drivingStyle=1"); else if (style == DRIVING_STYLE_AGGRESSIVE) - strcat(url, "&drivingStyle=3"); + STRCAT(url, "&drivingStyle=3"); int length = g_list_length(waypoints); if (length != 0) { @@ -86,7 +87,7 @@ int query_route(gchar *maps_key, coords_s startPoint, coords_s endPoint, route_t snprintf(tmpStr, sizeof(tmpStr), "&from=%f,%f", data->latitude, data->longitude); else snprintf(tmpStr, sizeof(tmpStr), "&to=%f,%f", data->latitude, data->longitude); - strcat(url, tmpStr); + STRCAT(url, tmpStr); } waypoints_list = g_list_next(waypoints_list); @@ -94,10 +95,10 @@ int query_route(gchar *maps_key, coords_s startPoint, coords_s endPoint, route_t } } else { snprintf(tmpStr, sizeof(tmpStr), "&from=%f,%f", startPoint.latitude, startPoint.longitude); - strcat(url, tmpStr); + STRCAT(url, tmpStr); snprintf(tmpStr, sizeof(tmpStr), "&to=%f,%f", endPoint.latitude, endPoint.longitude); - strcat(url, tmpStr); + STRCAT(url, tmpStr); } add_handle(url, REQ_TYPE_ROUTE, user_data); diff --git a/src/mapquest/mapquest_util.h b/src/mapquest/mapquest_util.h index b62a3d5..0f9e6b9 100644 --- a/src/mapquest/mapquest_util.h +++ b/src/mapquest/mapquest_util.h @@ -19,6 +19,9 @@ #include "mapquest_types.h" +#define STRCPY(buffer, string) strncpy(buffer, string, sizeof(buffer)-strlen(buffer)-1) +#define STRCAT(buffer, string) strncat(buffer, string, sizeof(buffer)-strlen(buffer)-1) + void calculate_point(gdouble Lat1, gdouble Lon1, int dBearing, gdouble dist, coords_s **coord); #endif /* _MAPQUEST_UTIL_H_ */ diff --git a/src/mapquest_plugin.c b/src/mapquest_plugin.c index 9b119f2..e08d4d1 100644 --- a/src/mapquest_plugin.c +++ b/src/mapquest_plugin.c @@ -19,6 +19,7 @@ #include "mapquest_plugin.h" #include "mapquest_plugin_internal.h" #include "mapquest_api.h" +#include "mapquest_util.h" #include #include #include @@ -457,71 +458,70 @@ EXPORT_API int maps_plugin_geocode_by_structured_address(const maps_address_h ad MAPS_PRINT_ERROR_CODE_RETURN(MAPS_ERROR_OUT_OF_MEMORY); } - char resultAddressQuery[1024]; - strcpy(resultAddressQuery, ""); + char resultAddressQuery[1024] = ""; char *street = NULL; maps_address_get_street(address, &street); if (street != NULL) - strcat(resultAddressQuery, street); + STRCAT(resultAddressQuery, street); char *city = NULL; maps_address_get_city(address, &city); if ((strlen(resultAddressQuery) > 0) && (city != NULL)) { - strcat(resultAddressQuery, ","); - strcat(resultAddressQuery, city); + STRCAT(resultAddressQuery, ","); + STRCAT(resultAddressQuery, city); } else if (city != NULL) { - strcat(resultAddressQuery, city); + STRCAT(resultAddressQuery, city); } char *state = NULL; maps_address_get_state(address, &state); if ((strlen(resultAddressQuery) > 0) && (state != NULL)) { - strcat(resultAddressQuery, ","); - strcat(resultAddressQuery, state); + STRCAT(resultAddressQuery, ","); + STRCAT(resultAddressQuery, state); } else if (state != NULL) { - strcat(resultAddressQuery, state); + STRCAT(resultAddressQuery, state); } #if 0 char *district = NULL; maps_address_get_district(address, &district); if ((strlen(resultAddressQuery) > 0) && (district != NULL)) { - strcat(resultAddressQuery, ", "); - strcat(resultAddressQuery, district); + STRCAT(resultAddressQuery, ", "); + STRCAT(resultAddressQuery, district); } char *country = NULL; maps_address_get_country(address, &country); if ((strlen(resultAddressQuery) > 0) && (country != NULL)) { - strcat(resultAddressQuery, ", "); - strcat(resultAddressQuery, country); + STRCAT(resultAddressQuery, ", "); + STRCAT(resultAddressQuery, country); } char *country_code = NULL; maps_address_get_country_code(address, &country_code); if ((strlen(resultAddressQuery) > 0) && (country_code != NULL)) { - strcat(resultAddressQuery, ", "); - strcat(resultAddressQuery, country_code); + STRCAT(resultAddressQuery, ", "); + STRCAT(resultAddressQuery, country_code); } else if (country_code != NULL) { - strcat(resultAddressQuery, country_code); + STRCAT(resultAddressQuery, country_code); } char *county = NULL; maps_address_get_county(address, &county); if ((strlen(resultAddressQuery) > 0) && (county != NULL)) { - strcat(resultAddressQuery, ", "); - strcat(resultAddressQuery, county); + STRCAT(resultAddressQuery, ", "); + STRCAT(resultAddressQuery, county); } #endif char *postal_code = NULL; maps_address_get_postal_code(address, &postal_code); if ((strlen(resultAddressQuery) > 0) && (postal_code != NULL)) { - strcat(resultAddressQuery, ","); - strcat(resultAddressQuery, postal_code); + STRCAT(resultAddressQuery, ","); + STRCAT(resultAddressQuery, postal_code); } else if (postal_code != NULL) { - strcat(resultAddressQuery, postal_code); + STRCAT(resultAddressQuery, postal_code); } char *modified_address = NULL; -- 2.7.4