[GRASS-SVN] r57267 - grass/trunk/imagery/i.segment
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Jul 25 03:30:27 PDT 2013
Author: mmetz
Date: 2013-07-25 03:30:27 -0700 (Thu, 25 Jul 2013)
New Revision: 57267
Modified:
grass/trunk/imagery/i.segment/write_output.c
Log:
i.segment: avoid integer overflow in Rast_make_random_colors()
Modified: grass/trunk/imagery/i.segment/write_output.c
===================================================================
--- grass/trunk/imagery/i.segment/write_output.c 2013-07-24 20:33:52 UTC (rev 57266)
+++ grass/trunk/imagery/i.segment/write_output.c 2013-07-25 10:30:27 UTC (rev 57267)
@@ -15,7 +15,7 @@
int write_output(struct globals *globals)
{
- int out_fd, row, col;
+ int out_fd, row, col, maxid;
CELL *outbuf, rid;
struct Colors colors;
struct History hist;
@@ -29,6 +29,7 @@
G_debug(1, "start data transfer from segmentation file to raster");
G_message(_("Writing out segment IDs"));
+ maxid = 0;
for (row = 0; row < globals->nrows; row++) {
G_percent(row, globals->nrows, 9);
@@ -41,6 +42,8 @@
if (rid > 0) {
outbuf[col] = rid;
+ if (maxid < rid)
+ maxid = rid;
}
}
}
@@ -53,7 +56,7 @@
/* set colors */
Rast_init_colors(&colors);
- Rast_make_random_colors(&colors, 1, globals->nrows * globals->ncols);
+ Rast_make_random_colors(&colors, 1, maxid);
Rast_write_colors(globals->out_name, G_mapset(), &colors);
Rast_short_history(globals->out_name, "raster", &hist);
More information about the grass-commit
mailing list