]> git.street.me.uk Git - andy/viking.git/commitdiff
SF Bugs#115: Fix application hanging on degrees input ending in a comma.
authorRob Norris <rw_norris@hotmail.com>
Sun, 2 Nov 2014 18:22:06 +0000 (18:22 +0000)
committerRob Norris <rw_norris@hotmail.com>
Sun, 2 Nov 2014 18:22:06 +0000 (18:22 +0000)
Need to detect when the processing endptr hasn't changed in analysing the text input,
 otherwise the while loop will get stuck in an infinite loop.

src/degrees_converters.c

index f78b178f9fb15d7dfecf0586f9cae98ca1e93a23..1703ef0e8d7df3ab93fd922865c593a661240627 100644 (file)
@@ -178,8 +178,13 @@ gdouble convert_dms_to_dec(const gchar *dms)
                        gdouble value;
                        ptr = strpbrk (endptr, "0123456789,.");
                        if (ptr != NULL) {
-                         value = g_strtod((const gchar *)ptr, (gchar **)&endptr);
-                       nbFloat++;
+                               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;