diff options
author | Zbigniew Chyla <zbigniew.chyla@nsn.com> | 2015-01-07 11:04:00 +0100 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2015-01-13 07:23:15 -0500 |
commit | 18d76d6bda59a9eb0a3f062fac91f481babcbdf4 (patch) | |
tree | bedf2bc28676681e73a8decc42c4c757faa47e2e /lcdgps.c | |
parent | 679ad1b39528615dbaeb22bc741b93dc3c3ee4fb (diff) | |
download | gpsd-18d76d6bda59a9eb0a3f062fac91f481babcbdf4.tar.gz |
Always use sizeof to get array size
Don't use constant/expression from an array's definition when referring
to its size. Eliminates redundancy and avoids problems when array size
changes. The change doesn't affect generated code.
Diffstat (limited to 'lcdgps.c')
-rw-r--r-- | lcdgps.c | 10 |
1 files changed, 5 insertions, 5 deletions
@@ -189,11 +189,11 @@ static void update_lcd(struct gps_data_t *gpsdata) char *s; s = deg_to_str(deg_type, fabs(gpsdata->fix.latitude)); - snprintf(tmpbuf, 254, "widget_set gpsd one 1 1 {Lat: %s %c}\n", s, (gpsdata->fix.latitude < 0) ? 'S' : 'N'); + snprintf(tmpbuf, sizeof(tmpbuf) - 1, "widget_set gpsd one 1 1 {Lat: %s %c}\n", s, (gpsdata->fix.latitude < 0) ? 'S' : 'N'); send_lcd(tmpbuf); s = deg_to_str(deg_type, fabs(gpsdata->fix.longitude)); - snprintf(tmpbuf, 254, "widget_set gpsd two 1 2 {Lon: %s %c}\n", s, (gpsdata->fix.longitude < 0) ? 'W' : 'E'); + snprintf(tmpbuf, sizeof(tmpbuf) - 1, "widget_set gpsd two 1 2 {Lon: %s %c}\n", s, (gpsdata->fix.longitude < 0) ? 'W' : 'E'); send_lcd(tmpbuf); /* As a pilot, a heading of "0" gives me the heebie-jeebies (ie, 0 @@ -201,7 +201,7 @@ static void update_lcd(struct gps_data_t *gpsdata) track=(int)(gpsdata->fix.track); if (track == 0) track = 360; - snprintf(tmpbuf, 254, "widget_set gpsd three 1 3 {%.1f %s %d deg}\n", + snprintf(tmpbuf, sizeof(tmpbuf) - 1, "widget_set gpsd three 1 3 {%.1f %s %d deg}\n", gpsdata->fix.speed*speedfactor, speedunits, track); send_lcd(tmpbuf); @@ -221,10 +221,10 @@ static void update_lcd(struct gps_data_t *gpsdata) avgclimb=0.0; for(n=0;n<CLIMB;n++) avgclimb+=climb[n]; avgclimb/=CLIMB; - snprintf(tmpbuf, 254, "widget_set gpsd four 1 4 {%d %s %s %d fpm }\n", + snprintf(tmpbuf, sizeof(tmpbuf) - 1, "widget_set gpsd four 1 4 {%d %s %s %d fpm }\n", (int)(gpsdata->fix.altitude*altfactor), altunits, gridsquare, (int)(avgclimb * METERS_TO_FEET * 60)); } else { - snprintf(tmpbuf, 254, "widget_set gpsd four 1 4 {n/a}\n"); + snprintf(tmpbuf, sizeof(tmpbuf) - 1, "widget_set gpsd four 1 4 {n/a}\n"); } send_lcd(tmpbuf); } |