Tests all passed, and I fixed gpsrinex.

I'll push this in 24h unless someone can explain why it's wrong or that
we should fix it differently, or right away on positive review.

commit 52a46358c8af3ee2d93fdfa854abe67277f82a15
Author: Greg Troxel <[email protected]>
Date:   Wed Oct 29 10:02:59 2025 -0400

    libgps/gpsutils.c: Fix ctype(3) UB
    
    Rather than assigning char to an int, and risking a value outside of
    the range of unsigned char plus EOF, just use an unsigned char
    intermediary.

diff --git a/libgps/gpsutils.c b/libgps/gpsutils.c
index 926ddf864..34091391a 100644
--- a/libgps/gpsutils.c
+++ b/libgps/gpsutils.c
@@ -312,7 +312,7 @@ double safe_atof(const char *string)
     bool sign = false, expSign = false;
     double fraction, dblExp, *d;
     const char *p;
-    int c;
+    unsigned char c;
     int exp = 0;                // Exponent read from "EX" field.
     int fracExp = 0;            /* Exponent that derives from the fractional
                                  * part.  Under normal circumstatnces, it is
@@ -337,7 +337,7 @@ double safe_atof(const char *string)
     while (isspace((int)*p)) {
         p += 1;
     }
-    if (isdigit((int)*p)) {
+    if (isdigit((unsigned char)*p)) {
         // ignore
     } else if ('-' == *p) {
         sign = true;
@@ -358,7 +358,7 @@ double safe_atof(const char *string)
     decPt = -1;
     for (mantSize = 0; ; mantSize += 1) {
         c = *p;
-        if (!isdigit((int)c)) {
+        if (!isdigit(c)) {
             if ((c != '.') || (decPt >= 0)) {
                 break;
             }
@@ -434,7 +434,7 @@ double safe_atof(const char *string)
             }
             expSign = false;
         }
-        while (isdigit((int) *p)) {
+        while (isdigit((unsigned char) *p)) {
             exp = exp * 10 + (*p - '0');
             if (1024 < exp) {
                 if (true == expSign) {

Reply via email to