[GRASS-dev] Re: [GRASS-user] Problem with r.reclas on ubuntu feisty

Jaros³aw Jasiewicz wrote:

I have problem with r.reclass (and r.reclas.rules) from latest cvs
(updated wensday morning)
on whatever map I use it I recive segmentation fault error

I confirm for current GRASS 6.3 CVS built and running on Ubuntu Dapper,
32 bit, GCC 4.0.3, Pentium M, kernel 2.6.15-28-686.

Any r.reclass session ends up with a segfault after the 'end' command;
eg. in spearfish:

$ r.reclass in=aspect output=tryit

1 thru 9.9 = 1

10.400000 rounded up to 10

30 thru 31 = 32
end

Segmentation fault

P.S.

Why "10.400000 rounded up to 10". I specified range "1 thru 9.9"...
Maciek

Maciej Sieczka wrote:

Jaros³aw Jasiewicz wrote:

> I have problem with r.reclass (and r.reclas.rules) from latest cvs
> (updated wensday morning)
> on whatever map I use it I recive segmentation fault error

I confirm for current GRASS 6.3 CVS built and running on Ubuntu
Dapper, 32 bit, GCC 4.0.3, Pentium M, kernel 2.6.15-28-686.

Any r.reclass session ends up with a segfault after the 'end' command;
eg. in spearfish:

$ r.reclass in=aspect output=tryit

> 1 thru 9.9 = 1
10.400000 rounded up to 10
> 30 thru 31 = 32
> end
Segmentation fault

Same here.

Working through a gdb session:

G63> gdb `which r.reclass`
...
(gdb) run in=aspect output=tryit
Starting program: /usr/local/src/grass/grass63/dist.i686-pc-linux-gnu/bin/r.reclass in=aspect output=tryit

Enter rule(s), "end" when done, "help" if you need it
fp: Data range is 0.0000000000000000000000000 to 360.0000000000000000000000000

1 thru 9.9 = 1

10.400000 rounded up to 10

30 thru 31 = 32
end

Program received signal SIGSEGV, Segmentation fault.
0x40121556 in strcpy () from /lib/libc.so.6

### see where it happened

(gdb) where
#0 0x40121556 in strcpy () from /lib/libc.so.6
#1 0x0804a922 in reclass (old_name=0x804c930 "aspect", old_mapset=0x804c750 "PERMANENT",
    new_name=0x804c940 "tryit", rules=0x804c790, cats=0xbffff570, title=0x0) at reclass.c:234
#2 0x08049933 in main (argc=4, argv=0xbffff6a4) at main.c:122

### in the current frame (#2) see where in the source code it was
### (main.c line 122, as shown above)

(gdb) list
122 reclass (parm.input->answer, old_mapset, parm.output->answer, rules, &cats, parm.ti tle->answer);
123
124 exit(EXIT_SUCCESS);
125 }

### main.c is just a wrapper, jump into the "#1" function as listed in
### the above "where". (#1 (...) at reclass.c:234)

(gdb) frame 1
#1 0x0804a922 in reclass (old_name=0x804c930 "aspect", old_mapset=0x804c750 "PERMANENT",
    new_name=0x804c940 "tryit", rules=0x804c790, cats=0xbffff570, title=0x0) at reclass.c:234
234 strcpy (new.name, old_name);

(gdb) list
229 strcpy (new.mapset, old.mapset);
230 re_reclass (rules, cats, &old, &new, old_name, old_mapset);
231 }
232 else
233 {
234 strcpy (new.name, old_name);
235 strcpy (new.mapset, old_mapset);
236 _reclass (rules, cats, &new);
237 }
238

### print the contents of the new.name and old_name variables

(gdb) p new.name
$1 = 0xfff098 <Address 0xfff098 out of bounds>
(gdb) p old_name
$3 = 0x804c930 "aspect"

### note there is also an "old.name" variable
(gdb) p old.name
$2 = 0x0

Memory was never allocated for the "new" Reclass struct??
so strcpy() tries to copy the string into unknown memory space, and fails.

Why "10.400000 rounded up to 10". I specified range "1 thru 9.9"...

no idea.

Hamish

Maciej Sieczka wrote:

> I have problem with r.reclass (and r.reclas.rules) from latest cvs
> (updated wensday morning)
> on whatever map I use it I recive segmentation fault error

I confirm for current GRASS 6.3 CVS built and running on Ubuntu Dapper,
32 bit, GCC 4.0.3, Pentium M, kernel 2.6.15-28-686.

Any r.reclass session ends up with a segfault after the 'end' command;
eg. in spearfish:

$ r.reclass in=aspect output=tryit

> 1 thru 9.9 = 1
10.400000 rounded up to 10
> 30 thru 31 = 32
> end
Segmentation fault

I changed the name/mapset fields in struct Reclass from fixed-size
char to dynamically-allocated char*. I missed some of the cases
which were relying upon the old structure (AFAICT, I got all of the
ones in libgis, but missed r.reclass).

This should be sufficient for r.reclass:

--- raster/r.reclass/reclass.c 15 Dec 2006 09:05:02 -0000 2.2
+++ raster/r.reclass/reclass.c 25 Apr 2007 22:49:33 -0000
@@ -200,8 +200,8 @@
{
     struct Reclass mid;

- strcpy(mid.name, input_name);
- strcpy(mid.mapset, input_mapset);
+ mid.name = G_store(input_name);
+ mid.mapset = G_store(input_mapset);

     _reclass(rules, cats, &mid);

@@ -225,14 +225,14 @@

     if (is_reclass)
     {
- strcpy (new.name, old.name);
- strcpy (new.mapset, old.mapset);
+ new.name = G_store(old.name);
+ new.mapset = G_store(old.mapset);
   re_reclass (rules, cats, &old, &new, old_name, old_mapset);
     }
     else
     {
- strcpy (new.name, old_name);
- strcpy (new.mapset, old_mapset);
+ new.name = G_store(old.name);
+ new.mapset = G_store(old.mapset);
   _reclass (rules, cats, &new);
     }

Now I need to go through and see what else I might have missed.

Why "10.400000 rounded up to 10". I specified range "1 thru 9.9"...
Maciek

Reclassing only works on integers; FP maps have to be quantised. This
is done by rounding to the nearest integer, i.e. adding 0.5 then
truncating. The code which prints the message uses the value after the
0.5 has been added to it. I'll look into that later.

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

Jarekj Jasiewicz wrote:

> This should be sufficient for r.reclass:

unfortunatly not, error remains

Oops:

--- raster/r.reclass/reclass.c 26 Apr 2007 00:16:16 -0000 2.3
+++ raster/r.reclass/reclass.c 26 Apr 2007 09:22:10 -0000
@@ -231,8 +231,8 @@
     }
     else
     {
- new.name = G_store(old.name);
- new.mapset = G_store(old.mapset);
+ new.name = G_store(old_name);
+ new.mapset = G_store(old_mapset);
   _reclass (rules, cats, &new);
     }

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