[Xastir-Dev] Bug report: WX format decoding error

Henk de Groot henk.de.groot at hetnet.nl
Wed Jun 4 17:25:04 EDT 2003


Hello Curt,

At 15:25 27-5-03 -0700, Curt Mills, WE7U wrote:
>Fixed.  Thanks for finding that!  Let us know if there are other
>similar things in the code.

Well, it did fix temperature and humidity, but not barometric pressure.
So I went into the code, the attached diff should fix it. This
is another potential cleanup area, I see duplicate checking now. I just
went ahead in the same vain as the existing code, the best way to
improve this is to only check the value on entry and make the string
length zero if it doesn't contain a value. Then we can forget about
the extra checks in the rest of the code.

Okay, here is the patch:

--- src/db.c.old        Sun Jun  1 23:33:28 2003
+++ src/db.c    Wed Jun  4 20:15:43 2003
@@ -3766,7 +3766,9 @@
         XmTextInsert(si_text,pos,temp);
         pos += strlen(temp);
 
-        if (strlen(weather->wx_gust) > 0) {
+        if ( (strlen(weather->wx_gust) > 0)
+             && (weather->wx_gust[0] != ' ')
+             && (weather->wx_gust[0] != '.') ) {
             if (units_english_metric)
                 xastir_snprintf(temp, sizeof(temp), langcode("WPUPSTI028"),weather->wx_gust);
             else
@@ -3822,7 +3824,9 @@
             pos += strlen(temp);
         }
 
-        if (strlen(weather->wx_baro) > 0) {
+        if ( (strlen(weather->wx_baro) > 0)
+             && (weather->wx_baro[0] != ' ')
+             && (weather->wx_baro[0] != '.') ) {
             if (!units_english_metric) {  // hPa
                 xastir_snprintf(temp, sizeof(temp),
                     langcode("WPUPSTI033"),
@@ -3846,7 +3850,9 @@
             }
         }
 
-        if (strlen(weather->wx_snow) > 0) {
+        if ( (strlen(weather->wx_snow) > 0)
+             && (weather->wx_snow[0] != ' ')
+             && (weather->wx_snow[0] != '.') ) {
             if(units_english_metric)
                 xastir_snprintf(temp, sizeof(temp), langcode("WPUPSTI035"),atof(weather->wx_snow)/100.0);
             else
@@ -3858,14 +3864,25 @@
             pos += strlen(temp);
         }
 
-        if (strlen(weather->wx_rain) > 0 || strlen(weather->wx_prec_00) > 0
-                || strlen(weather->wx_prec_24) > 0) {
+        if ( ( (strlen(weather->wx_rain) > 0)
+               && (weather->wx_rain[0] != ' ')
+               && (weather->wx_rain[0] != '.') )
+             ||
+             ( (strlen(weather->wx_prec_00) > 0)
+               && (weather->wx_prec_00[0] != ' ')
+               && (weather->wx_prec_00[0] != '.') )
+             ||
+             ( (strlen(weather->wx_prec_24) > 0)
+               && (weather->wx_prec_24[0] != ' ')
+               && (weather->wx_prec_24[0] != '.') ) ) {
             xastir_snprintf(temp, sizeof(temp), langcode("WPUPSTI036"));
             XmTextInsert(si_text,pos,temp);
             pos += strlen(temp);
         }
 
-        if (strlen(weather->wx_rain) > 0) {
+        if ( (strlen(weather->wx_rain) > 0)
+             && (weather->wx_rain[0] != ' ')
+             && (weather->wx_rain[0] != '.') ) {
             if (units_english_metric)
                 xastir_snprintf(temp, sizeof(temp), langcode("WPUPSTI038"),atof(weather->wx_rain)/100.0);
             else
@@ -3875,7 +3892,9 @@
             pos += strlen(temp);
         }
 
-        if (strlen(weather->wx_prec_24) > 0) {
+        if ( (strlen(weather->wx_prec_24) > 0)
+             && (weather->wx_prec_24[0] != ' ')
+             && (weather->wx_prec_24[0] != '.') ) {
             if(units_english_metric)
                 xastir_snprintf(temp, sizeof(temp), langcode("WPUPSTI040"),atof(weather->wx_prec_24)/100.0);
             else
@@ -3885,7 +3904,9 @@
             pos += strlen(temp);
         }
 
-        if (strlen(weather->wx_prec_00) > 0) {
+        if ( (strlen(weather->wx_prec_00) > 0)
+             && (weather->wx_prec_00[0] != ' ')
+             && (weather->wx_prec_00[0] != '.') ) {
             if (units_english_metric)
                 xastir_snprintf(temp, sizeof(temp), langcode("WPUPSTI042"),atof(weather->wx_prec_00)/100.0);
             else
@@ -3895,7 +3916,9 @@
             pos += strlen(temp);
         }
 
-        if (strlen(weather->wx_rain_total) > 0) {
+        if ( (strlen(weather->wx_rain_total) > 0)
+             && (weather->wx_rain_total[0] != ' ')
+             && (weather->wx_rain_total[0] != '.') ) {
             xastir_snprintf(temp, sizeof(temp), "\n%s",langcode("WPUPSTI046"));
             XmTextInsert(si_text,pos,temp);
             pos += strlen(temp);
@@ -5025,10 +5048,16 @@
         }
 
         if (extract_weather_item(data,'b',5,weather->wx_baro))  // barometric pressure (1/10 mbar / 1/10 hPascal)
-            xastir_snprintf(weather->wx_baro,
-                sizeof(weather->wx_baro),
-                "%0.1f",
-                (float)(atoi(weather->wx_baro)/10.0));
+            if (weather->wx_baro[0] != '.'
+                    && weather->wx_baro[0] != ' ') {
+                xastir_snprintf(weather->wx_baro,
+                    sizeof(weather->wx_baro),
+                    "%0.1f",
+                    (float)(atoi(weather->wx_baro)/10.0));
+            }
+            else {  // Truncate it
+                weather->wx_baro[0] = '\0';
+            }
 
         (void)extract_weather_item(data,'s',3,weather->wx_snow);      // snowfall (in inches) in the last 24 hours
                                                                       // was 1/100 inch, APRS reference says inch! ??
@@ -5216,13 +5245,16 @@
        // Pressure is already in millibars/hPa.  No conversion
         // needed.
         if (extract_weather_item(p2,'/',4,weather->wx_baro))  // barometric pressure (1/10 mbar / 1/10 hPascal)
-            xastir_snprintf(weather->wx_baro,
-                sizeof(weather->wx_baro),
-                "%0.1f",
-                (float)(atoi(weather->wx_baro)));
-        if ( (weather->wx_baro[0] == '.')
-                || (weather->wx_baro[0] == ' ') )
-            weather->wx_baro[0] = '\0';
+            if (weather->wx_baro[0] != '.'
+                    && weather->wx_baro[0] != ' ') {
+                xastir_snprintf(weather->wx_baro,
+                    sizeof(weather->wx_baro),
+                    "%0.1f",
+                    (float)(atoi(weather->wx_baro)));
+            }
+            else {  // Truncate it
+                weather->wx_baro[0] = '\0';
+            }
 
 //fprintf(stderr,"%s\n",data);
 



Kind regards,

Henk.



More information about the Xastir-dev mailing list