diff options
author | Joseph Herlant <aerostitch@users.noreply.github.com> | 2018-09-11 22:26:26 -0600 |
---|---|---|
committer | Pierre GRANDIN <pgrandin@users.noreply.github.com> | 2018-09-11 21:26:26 -0700 |
commit | 07de185df5dc96356a21016b544137b84b4fc023 (patch) | |
tree | aa01e3ca642b91fc5e55443a9f5e1167cf817555 | |
parent | 669e060bddd09feb27a7c7df50f21b7ea63483c9 (diff) | |
download | navit-07de185df5dc96356a21016b544137b84b4fc023.tar.gz |
cleanup:core:Make sure we use g_* for malloc/free/strncpy (#663)
* cleanup:coord:Make sure we use g_* for malloc/free
* cosmetic:coord:Fix some function declaration format
* cleanup:coord:Move from strncpy to g_strlcpy
-rw-r--r-- | navit/coord.c | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/navit/coord.c b/navit/coord.c index 3d2a93ad7..bb16978c8 100644 --- a/navit/coord.c +++ b/navit/coord.c @@ -39,15 +39,13 @@ * @returns the coordinate */ -struct coord * -coord_get(unsigned char **p) { +struct coord * coord_get(unsigned char **p) { struct coord *ret=(struct coord *)(*p); *p += sizeof(*ret); return ret; } -struct coord * -coord_new(int x, int y) { +struct coord * coord_new(int x, int y) { struct coord *c=g_new(struct coord, 1); c->x=x; @@ -56,8 +54,7 @@ coord_new(int x, int y) { return c; } -struct coord * -coord_new_from_attrs(struct attr *parent, struct attr **attrs) { +struct coord * coord_new_from_attrs(struct attr *parent, struct attr **attrs) { struct attr *x,*y; x=attr_search(attrs, NULL, attr_x); y=attr_search(attrs, NULL, attr_y); @@ -71,8 +68,7 @@ void coord_destroy(struct coord *c) { g_free(c); } -struct coord_rect * -coord_rect_new(struct coord *lu, struct coord *rl) { +struct coord_rect * coord_rect_new(struct coord *lu, struct coord *rl) { struct coord_rect *r=g_new(struct coord_rect, 1); dbg_assert(lu->x <= rl->x); @@ -160,9 +156,8 @@ int coord_parse(const char *coord_input, enum projection output_projection, stru s=strchr(str,' '); co=strchr(str,':'); if (co && co < s) { - proj=malloc(co-str+1); - strncpy(proj, str, co-str); - proj[co-str]='\0'; + proj=g_malloc(co-str+1); + g_strlcpy(proj, str, 1+co-str); dbg(lvl_debug,"projection=%s", proj); str=co+1; s=strchr(str,' '); @@ -250,7 +245,7 @@ int coord_parse(const char *coord_input, enum projection output_projection, stru ret+=str-coord_input; dbg(lvl_info, "ret=%d delta=%d ret_str='%s'", ret, GPOINTER_TO_INT(str-coord_input), coord_input+ret); out: - free(proj); + g_free(proj); return ret; } |