X-Git-Url: https://git.street.me.uk/andy/viking.git/blobdiff_plain/a58aaed47ff23aa3e607fd2d9583d3345ae6453a..0a25e23214e753d9190e33e58b23685783099bd5:/src/degrees_converters.c diff --git a/src/degrees_converters.c b/src/degrees_converters.c index 73463826..9e55a399 100644 --- a/src/degrees_converters.c +++ b/src/degrees_converters.c @@ -18,10 +18,15 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#ifdef HAVE_MATH_H #include -#include +#endif #include +#include "degrees_converters.h" #define DEGREE_SYMBOL "\302\260" @@ -129,11 +134,11 @@ static gchar *convert_dec_to_dms(gdouble dec, gchar pos_c, gchar neg_c) tmp = (tmp - val_d) * 60; val_m = (gint)tmp; - /* Minutes */ + /* Seconds */ val_s = (tmp - val_m) * 60; /* Format */ - result = g_strdup_printf ( "%c%d" DEGREE_SYMBOL "%d'%f\"", + result = g_strdup_printf ( "%c%d" DEGREE_SYMBOL "%d'%.4f\"", sign_c, val_d, val_m, val_s ); return result; } @@ -173,8 +178,13 @@ gdouble convert_dms_to_dec(const gchar *dms) gdouble value; ptr = strpbrk (endptr, "0123456789,."); if (ptr != NULL) { - value = g_strtod(ptr, &endptr); - nbFloat++; + const gchar *tmpptr = endptr; + value = g_strtod((const gchar *)ptr, (gchar **)&endptr); + // Detect when endptr hasn't changed (which may occur if no conversion took place) + // particularly if the last character is a ',' or there are multiple '.'s like '5.5.' + if ( endptr == tmpptr ) + break; + nbFloat++; switch(nbFloat) { case 1: d = value; @@ -185,6 +195,7 @@ gdouble convert_dms_to_dec(const gchar *dms) case 3: s = value; break; + default: break; } } } while (ptr != NULL && endptr != NULL);