[GRASS-SVN] r54906 - grass/trunk/display/d.vect
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Feb 4 08:15:37 PST 2013
Author: mmetz
Date: 2013-02-04 08:15:37 -0800 (Mon, 04 Feb 2013)
New Revision: 54906
Modified:
grass/trunk/display/d.vect/label.c
Log:
d.vect: fix sprintf abuse
Modified: grass/trunk/display/d.vect/label.c
===================================================================
--- grass/trunk/display/d.vect/label.c 2013-02-04 16:10:13 UTC (rev 54905)
+++ grass/trunk/display/d.vect/label.c 2013-02-04 16:15:37 UTC (rev 54906)
@@ -80,8 +80,8 @@
const struct line_cats *Cats, LATTR *lattr,
int chcat, const struct cat_list *Clist)
{
- int i, cat;
- char text[100];
+ int i, cat, len;
+ char *text = NULL, buf[100];
D_RGB_color(lattr->color.R, lattr->color.G, lattr->color.B);
D_text_size(lattr->size, lattr->size);
@@ -118,19 +118,29 @@
}
if (Vect_cat_get(Cats, lattr->field, &cat)) {
- text[0] = '\0';
for (i = 0; i < Cats->n_cats; i++) {
G_debug(3, "cat lab: field = %d, cat = %d", Cats->field[i],
Cats->cat[i]);
if (Cats->field[i] == lattr->field) { /* all cats of given lfield */
- if (*text != '\0')
- sprintf(text, "%s/", text);
-
- sprintf(text, "%s%d", text, Cats->cat[i]);
+ if (!text) {
+ sprintf(buf, "%d", Cats->cat[i]);
+ text = G_calloc(strlen(buf), sizeof(char));
+ text[0] = '\0';
+ strcpy(text, buf);
+ }
+ else {
+ sprintf(buf, "/%d", Cats->cat[i]);
+ len = strlen(text) + strlen(buf) + 1;
+ text = G_realloc(text, len * sizeof(char));
+ strcat(text, buf);
+ }
}
}
show_label_line(Points, ltype, lattr, text);
}
+
+ if (text)
+ G_free(text);
return 1;
}
More information about the grass-commit
mailing list