]> err.no Git - mapper/commitdiff
Use static buffer instead of constantly malloc/free:ing
authorKaj-Michael Lang <milang@onion.tal.org>
Mon, 1 Oct 2007 11:38:27 +0000 (14:38 +0300)
committerKaj-Michael Lang <milang@onion.tal.org>
Mon, 1 Oct 2007 11:38:27 +0000 (14:38 +0300)
src/gps-panels.c

index db495c5cb552bcedcf63479137bdde61f87f900f..aaa423ee5417712f8f5d698dfaaace29982cf165 100644 (file)
@@ -34,7 +34,6 @@ static GtkWidget *text_alt;
 static GtkWidget *text_dop;
 static GtkWidget *text_time;
 static GtkWidget *sat_panel;
-static GtkWidget *heading_panel;
 
 static void gps_clear_text_fields(void);
 
@@ -93,23 +92,22 @@ return vbox;
 void
 gps_display_data_speed(GtkWidget *widget, gfloat s)
 {
-gchar *buffer;
+gchar buffer[32];
 gfloat speed = s * UNITS_CONVERT[_units];
 
 switch (_units) {
        case UNITS_MI:
-               buffer = g_strdup_printf("%.1f mph", speed);
-               break;
+               g_snprintf(buffer, 32, "%.1f mph", speed);
+       break;
        case UNITS_NM:
-               buffer = g_strdup_printf("%.1f kn", speed);
-               break;
+               g_snprintf(buffer, 32, "%.1f kn", speed);
+       break;
        default:
-               buffer = g_strdup_printf("%.1f km/h", speed);
-               break;
+               g_snprintf(buffer, 32, "%.1f km/h", speed);
+       break;
        }
 
 gtk_label_set_label(GTK_LABEL(widget), buffer);
-g_free(buffer);
 }
 
 static void
@@ -196,7 +194,7 @@ else {
 gboolean
 gps_display_details(void)
 {
-gchar *buffer, litbuf[16];
+gchar buffer[32];
 
 if (_gps.fix < 2) {
        /* no fix no fun */
@@ -208,12 +206,12 @@ if (_gps.fix < 2) {
        gtk_label_set_label(GTK_LABEL(_sdi_tim), " --:--:-- ");
 } else {
        /* latitude */
-       lat_format(_gps.lat, litbuf);
-       gtk_label_set_label(GTK_LABEL(_sdi_lat), litbuf);
+       lat_format(_gps.lat, buffer);
+       gtk_label_set_label(GTK_LABEL(_sdi_lat), buffer);
 
        /* longitude */
-       lon_format(_gps.lon, litbuf);
-       gtk_label_set_label(GTK_LABEL(_sdi_lon), litbuf);
+       lon_format(_gps.lon, buffer);
+       gtk_label_set_label(GTK_LABEL(_sdi_lon), buffer);
 
        /* speed */
        gps_display_data_speed(_sdi_spd, _gps.speed);
@@ -222,83 +220,77 @@ if (_gps.fix < 2) {
        switch (_units) {
        case UNITS_MI:
        case UNITS_NM:
-               buffer = g_strdup_printf("%.1f ft", _pos.altitude * 3.2808399f);
-               break;
+               g_snprintf(buffer, 32, "%.1f ft", _pos.altitude * 3.2808399f);
+       break;
        default:
-               buffer = g_strdup_printf("%.1f m", _pos.altitude);
-               break;
+               g_snprintf(buffer, 32, "%.1f m", _pos.altitude);
+       break;
        }
        gtk_label_set_label(GTK_LABEL(_sdi_alt), buffer);
-       g_free(buffer);
 
        /* heading */
-       buffer = g_strdup_printf("%0.0f° (%0.0f)", _gps.heading, fabs(_gps.heading-_gps.lheading));
+       g_snprintf(buffer, 32, "%0.0f° (%0.0f)", _gps.heading, fabs(_gps.heading-_gps.lheading));
        gtk_label_set_label(GTK_LABEL(_sdi_hea), buffer);
-       g_free(buffer);
 
        /* local time */
-       strftime(litbuf, 15, "%X", localtime(&_pos.time));
-       gtk_label_set_label(GTK_LABEL(_sdi_tim), litbuf);
+       strftime(buffer, 15, "%X", localtime(&_pos.time));
+       gtk_label_set_label(GTK_LABEL(_sdi_tim), buffer);
 }
 
 /* Sat in view */
-buffer = g_strdup_printf("%d", _gps.satinview);
+g_snprintf(buffer, 32, "%d", _gps.satinview);
 gtk_label_set_label(GTK_LABEL(_sdi_vie), buffer);
-g_free(buffer);
 
 /* Sat in use */
-buffer = g_strdup_printf("%d", _gps.satinuse);
+g_snprintf(buffer, 32, "%d", _gps.satinuse);
 gtk_label_set_label(GTK_LABEL(_sdi_use), buffer);
-g_free(buffer);
 
 /* fix */
 switch (_gps.fix) {
 case 2:
 case 3:
-       buffer = g_strdup_printf("%dD fix", _gps.fix);
-       break;
+       g_snprintf(buffer, 32, "%dD fix", _gps.fix);
+break;
 default:
-       buffer = g_strdup_printf("nofix");
-       break;
+       g_snprintf(buffer, 32, "nofix");
+break;
 }
 gtk_label_set_label(GTK_LABEL(_sdi_fix), buffer);
-g_free(buffer);
 
 if (_gps.fix == 1)
-       buffer = g_strdup("none");
+       g_snprintf(buffer, 32, "none");
 else {
        switch (_gps.fixquality) {
        case 1:
-               buffer = g_strdup(_("SPS"));
-               break;
+               g_strlcat(buffer,_("SPS"),32);
+       break;
        case 2:
-               buffer = g_strdup(_("DGPS"));
-               break;
+               g_strlcat(buffer,_("DGPS"),32);
+       break;
        case 3:
-               buffer = g_strdup(_("PPS"));
-               break;
+               g_strlcat(buffer,_("PPS"),32);
+       break;
        case 4:
-               buffer = g_strdup(_("Real Time Kinematic"));
-               break;
+               g_strlcat(buffer,_("Real Time Kinematic"),32);
+       break;
        case 5:
-               buffer = g_strdup(_("Float RTK"));
-               break;
+               g_strlcat(buffer,_("Float RTK"),32);
+       break;
        case 6:
-               buffer = g_strdup(_("Estimated"));
-               break;
+               g_strlcat(buffer,_("Estimated"),32);
+       break;
        case 7:
-               buffer = g_strdup(_("Manual"));
-               break;
+               g_strlcat(buffer,_("Manual"),32);
+       break;
        case 8:
-               buffer = g_strdup(_("Simulation"));
-               break;
+               g_strlcat(buffer,_("Simulation"),32);
+       break;
        default:
-               buffer = g_strdup(_("none"));
-               break;
+               g_strlcat(buffer,_("none"),32);
+       break;
        }
 }
 gtk_label_set_label(GTK_LABEL(_sdi_fqu), buffer);
-g_free(buffer);
 
 /* max speed */
 gps_display_data_speed(_sdi_msp, _gps.maxspeed);