[GRASS-SVN] r59116 - grass/trunk/vector/v.colors

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Feb 21 12:06:38 PST 2014


Author: martinl
Date: 2014-02-21 12:06:37 -0800 (Fri, 21 Feb 2014)
New Revision: 59116

Modified:
   grass/trunk/vector/v.colors/read_rgb.c
   grass/trunk/vector/v.colors/scan_attr.c
   grass/trunk/vector/v.colors/v.colors.html
Log:
v.colors: fix segfault when converting RGB values into color table


Modified: grass/trunk/vector/v.colors/read_rgb.c
===================================================================
--- grass/trunk/vector/v.colors/read_rgb.c	2014-02-21 18:11:40 UTC (rev 59115)
+++ grass/trunk/vector/v.colors/read_rgb.c	2014-02-21 20:06:37 UTC (rev 59116)
@@ -8,7 +8,7 @@
 void rgb2colr(const struct Map_info *Map, int layer, const char *rgb_column,
 	      struct Colors *colors)
 {
-    int i, ret;
+    int i, ret, nskipped;
     int red, grn, blu;
     const char *rgb;
     
@@ -39,21 +39,30 @@
     Rast_init_colors(colors);
     
     cv = NULL;
+    nskipped = 0;
     for (i = 0; i < cvarr.n_values; i++) {
 	cv = &(cvarr.value[i]);
 	rgb = db_get_string(cv->val.s);
 	G_debug(3, "cat = %d RGB = %s", cv->cat, rgb);
 
+        if (!rgb) {
+            nskipped++;
+            continue;
+        }
+        
 	ret = G_str_to_color(rgb, &red, &grn, &blu);
 	if (ret != 1) {
-	    G_warning(_("Invalid RGB value '%s'"), rgb);
+	    G_debug(3, "Invalid RGB value '%s'", rgb);
+            nskipped++;
 	    continue;
 	}
 
 	Rast_add_c_color_rule((const CELL*) &(cv->cat), red, grn, blu,
 			      (const CELL*) &(cv->cat), red, grn, blu, colors);
+    }
 
-    }
+    if (nskipped > 0)
+        G_warning(_("%d invalid RGB color values skipped"), nskipped);
     
     db_close_database_shutdown_driver(driver);
 }

Modified: grass/trunk/vector/v.colors/scan_attr.c
===================================================================
--- grass/trunk/vector/v.colors/scan_attr.c	2014-02-21 18:11:40 UTC (rev 59115)
+++ grass/trunk/vector/v.colors/scan_attr.c	2014-02-21 20:06:37 UTC (rev 59116)
@@ -104,6 +104,7 @@
     int red, grn, blu;
 
     /* color table for categories */
+    G_message(_("Converting color rules into categories..."));
     for (i = 0; i < cvarr->n_values; i++) {
 	cv = &(cvarr->value[i]);
 	cat = cv->cat;

Modified: grass/trunk/vector/v.colors/v.colors.html
===================================================================
--- grass/trunk/vector/v.colors/v.colors.html	2014-02-21 18:11:40 UTC (rev 59115)
+++ grass/trunk/vector/v.colors/v.colors.html	2014-02-21 20:06:37 UTC (rev 59116)
@@ -68,7 +68,7 @@
 3|3|0|87572.882812|4|3|NC097|212:42:127
 </pre></div>
 
-<h3>Convert color table into RGB values</h3>
+<h3>Convert RGB attribute values into color table</h3>
 
 Convert existing RGB values to color table rules.
 



More information about the grass-commit mailing list