[dia] [warningectomy] get rid of 'format not a string literal'
- From: Hans Breuer <hans src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dia] [warningectomy] get rid of 'format not a string literal'
- Date: Fri, 6 Aug 2010 11:43:31 +0000 (UTC)
commit 39159556d2ebaedfac5c67e17945006fbb3ce043
Author: Hans Breuer <hans breuer org>
Date: Fri Aug 6 13:38:54 2010 +0200
[warningectomy] get rid of 'format not a string literal'
No more "warning: format not a string literal, argument
types not checked"
One part is using "%.*g" giving precision and value as parameter
instead of two different homegrown solutions.
The other part was just leaky code needing a bit of restructuring.
app/app_procs.c | 10 ++++++++--
objects/Misc/measure.c | 5 +----
objects/chronogram/chronoref.c | 8 ++++----
3 files changed, 13 insertions(+), 10 deletions(-)
---
diff --git a/app/app_procs.c b/app/app_procs.c
index 1f5e0c8..42645be 100644
--- a/app/app_procs.c
+++ b/app/app_procs.c
@@ -865,12 +865,18 @@ app_init (int argc, char **argv)
g_free(export_format_string);
if (version) {
+ gchar *ver_utf8;
+ gchar *ver_locale;
#if (defined __TIME__) && (defined __DATE__)
/* TRANSLATOR: 2nd and 3rd %s are time and date respectively. */
- printf(g_locale_from_utf8(_("Dia version %s, compiled %s %s\n"), -1, NULL, NULL, NULL), VERSION, __TIME__, __DATE__);
+ ver_utf8 = g_strdup_printf(_("Dia version %s, compiled %s %s\n"), VERSION, __TIME__, __DATE__);
#else
- printf(g_locale_from_utf8(_("Dia version %s\n"), -1, NULL, NULL, NULL), VERSION);
+ ver_utf8 = g_strdup_printf(_("Dia version %s\n"), VERSION);
#endif
+ ver_locale = g_locale_from_utf8(ver_utf8, -1, NULL, NULL, NULL);
+ printf("%s\n", ver_locale);
+ g_free(ver_locale);
+ g_free(ver_utf8);
if (verbose)
dump_dependencies();
exit(0);
diff --git a/objects/Misc/measure.c b/objects/Misc/measure.c
index e6fe11e..4c07af5 100644
--- a/objects/Misc/measure.c
+++ b/objects/Misc/measure.c
@@ -218,13 +218,10 @@ measure_update_data (Measure *measure)
Rectangle bbox;
Arrow arrow = MEASURE_ARROW(measure);
real ascent, width;
- gchar format[] = "%.3g %s";
g_return_if_fail (obj->handles != NULL);
connection_update_handles(conn);
- format[2] = measure->precision + '0';
-
extra->start_trans =
extra->end_trans =
extra->start_long =
@@ -234,7 +231,7 @@ measure_update_data (Measure *measure)
value = distance_point_point (&ends[0], &ends[1]);
value *= measure->scale;
value *= (28.346457 / units[measure->unit].factor);
- measure->name = g_strdup_printf (format, value, units[measure->unit].unit);
+ measure->name = g_strdup_printf ("%.*g %s", measure->precision, value, units[measure->unit].unit);
ascent = dia_font_ascent (measure->name, measure->font, measure->font_height);
width = dia_font_string_width (measure->name, measure->font, measure->font_height);
diff --git a/objects/chronogram/chronoref.c b/objects/chronogram/chronoref.c
index e1e98ed..cefc253 100644
--- a/objects/chronogram/chronoref.c
+++ b/objects/chronogram/chronoref.c
@@ -70,7 +70,7 @@ typedef struct _Chronoref {
real majgrad_height,mingrad_height;
real firstmaj,firstmin; /* in time units */
real firstmaj_x,firstmin_x,majgrad,mingrad; /* in dia graphic units */
- char spec[10];
+ int spec;
} Chronoref;
static real chronoref_distance_from(Chronoref *chronoref, Point *point);
@@ -312,7 +312,7 @@ chronoref_draw(Chronoref *chronoref, DiaRenderer *renderer)
p3.x = p2.x = p1.x;
renderer_ops->draw_line(renderer,&p1,&p2,&chronoref->color);
- g_snprintf(time,sizeof(time),chronoref->spec,t);
+ g_snprintf(time,sizeof(time),"%.*f",chronoref->spec,t);
renderer_ops->draw_string(renderer,time,&p3,ALIGN_CENTER,
&chronoref->font_color);
}
@@ -348,8 +348,8 @@ chronoref_update_data(Chronoref *chronoref)
t /= 10;
i++;
}
- g_snprintf(chronoref->spec,sizeof(chronoref->spec),"%%.%df",i);
- g_snprintf(biglabel,sizeof(biglabel),chronoref->spec,
+ chronoref->spec = i; /* update precision */
+ g_snprintf(biglabel,sizeof(biglabel),"%.*f", chronoref->spec,
MIN(-ABS(chronoref->start_time),-ABS(chronoref->end_time)));
labelwidth = dia_font_string_width(biglabel,chronoref->font,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]