[GRASS-dev] r.resamp.stats bus error

Glynn Clements glynn at gclements.plus.com
Tue Oct 21 07:19:35 EDT 2008


Jamie Adams wrote:

> This GDB was configured as "x86_64-linux"...
> (gdb) run -w input=W080N50 output=temp
> Starting program: /usr/local/grass-6.4.svn/bin/r.resamp.stats -w
> input=W080N50 output=temp
>    0%
> Program received signal SIGSEGV, Segmentation fault.
> 0x00007f8c4f2682a8 in transfer_to_cell_id (fd=<value optimized out>,
> cell=0xa1) at get_row.c:571
> 571             ((DCELL *) cell)[i] = ((CELL *) G__.work_buf)[i];
> (gdb) where
> #0  0x00007f8c4f2682a8 in transfer_to_cell_id (fd=<value optimized out>,
> cell=0xa1) at get_row.c:571
> #1  0x00007f8c4f26899d in get_map_row_nomask (fd=6, rast=0xa1, row=<value
> optimized out>, data_type=<value optimized out>) at get_row.c:633
> #2  0x00007f8c4f269279 in get_map_row (fd=6, rast=0xa1, row=6, data_type=2,
> null_is_zero=0, with_mask=1) at get_row.c:646
> #3  0x0000000000402256 in main (argc=<value optimized out>, argv=<value
> optimized out>) at main.c:192

Okay. AFAICT, there are two likely possibilities. One is that the
array element bufs[i] is getting corrupted, the other is that it is
outside of the bounds of the array.

I suspect the latter; the g.region/r.info output indicates a scale
factor of 24000:12001 ~= 1.9998333. This will result in it allocating
ceil(1.9998333) + 1 = 3 rows, which should be enough regardless of the
position of the input window. However, it's possible that rounding
errors are causing it to go slightly over.

Assuming that's what's happening, the following change should fix it:

--- raster/r.resamp.stats/main.c	(revision 33947)
+++ raster/r.resamp.stats/main.c	(working copy)
@@ -315,8 +315,8 @@
 
     G_set_window(&src_w);
 
-    row_scale = 1 + ceil(dst_w.ns_res / src_w.ns_res);
-    col_scale = 1 + ceil(dst_w.ew_res / src_w.ew_res);
+    row_scale = 2 + ceil(dst_w.ns_res / src_w.ns_res);
+    col_scale = 2 + ceil(dst_w.ew_res / src_w.ew_res);
 
     /* allocate buffers for input rows */
     bufs = G_malloc(row_scale * sizeof(DCELL *));

-- 
Glynn Clements <glynn at gclements.plus.com>


More information about the grass-dev mailing list