[GRASS-dev] [bug #4868] (grass) r.mapcalc: segfault in 'if then'

glynn@gclements.plus.com wrote (Wed, Jul 19 2006 09:44:55):

> r.mapcalc 'map=if(dtm,1)'
> Segmentation fault

I am unable to reproduce this.

Please provide a recipe to reproduce this with either the Spearfish
sample data or self-generated data.

Indeed, this is not 100% reproducible. Somehow it depends on a combination of
input/output raster name lenght and the raster type (double/float/integer).

Scenario for spearfish60:

$ g.region rast=aspect

$ r.mapcalc 'aspect_dbl=double(aspect)'

             35 CHARS LONG OUTPUT NAME:

$ r.mapcalc 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=if(aspect_dbl,1)'
100%

             36 CHARS:

$ r.mapcalc 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=if(aspect_dbl,1)'
*** glibc detected *** malloc(): memory corruption (fast): 0x0805a168 ***
Aborted

             37 CHARS AND MORE:

$ r.mapcalc 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=if(aspect_dbl,1)'
Segmentation fault

Maciek

-------------------------------------------- Managed by Request Tracker

Maciek Sieczka via RT wrote:

> > r.mapcalc 'map=if(dtm,1)'
> > Segmentation fault
>
> I am unable to reproduce this.
>
> Please provide a recipe to reproduce this with either the Spearfish
> sample data or self-generated data.

Indeed, this is not 100% reproducible. Somehow it depends on a combination of
input/output raster name lenght and the raster type (double/float/integer).

Okay, found it. The type inference code for if() was assigning types
to the 2nd/3rd/4th arguments regardless of whether that many arguments
were actually present, overflowing the array.

I've committed a fix to CVS.

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

Glynn Clements napisa?(a):

Maciek Sieczka via RT wrote:

r.mapcalc 'map=if(dtm,1)'
Segmentation fault

I am unable to reproduce this.

Please provide a recipe to reproduce this with either the Spearfish
sample data or self-generated data.

Indeed, this is not 100% reproducible. Somehow it depends on a combination of
input/output raster name lenght and the raster type (double/float/integer).

Okay, found it. The type inference code for if() was assigning types
to the 2nd/3rd/4th arguments regardless of whether that many arguments
were actually present, overflowing the array.

I've committed a fix to CVS.

Great, thanks!

Maciek