[GRASS-dev] [GRASS GIS] #455: d.what.rast segfault

#455: d.what.rast segfault
-------------------------+--------------------------------------------------
Reporter: hamish | Owner: grass-dev@lists.osgeo.org
     Type: defect | Status: new
Priority: major | Milestone: 6.4.0
Component: default | Version: unspecified
Keywords: | Platform: Unspecified
      Cpu: Unspecified |
-------------------------+--------------------------------------------------
Hi,

d.what.rast segfaults for me in latest develbranch6, but not in 6.3.0 or
6.4.0RC2.

spearfish:
{{{
g.region rast=elevation.dem
r.param.scale in=elevation.dem out=elev.asp_param param=aspect
d.mon x0
d.rast elev.asp_param
d.what.rast

Buttons
  Left: what's here
  Right: quit

603131.5625(E) 4924637.1875(N)
elev.asp_param@user1 in user1, quant (-59)
Segmentation fault
}}}

"map@mapset in mapset"??

{{{
(gdb) bt
#0 0xb7f0e72a in G_get_raster_cat (rast=0x80598f0, pcats=0x8051b68,
data_type=2)
     at cats.c:673
#1 0xb7f0e675 in G_get_d_raster_cat (rast=0x80598f0, pcats=0x8051b68) at
cats.c:636
#2 0x0804aca3 in what (once=0, terse=0, colrow=0, fs=0x804af63 ":",
width=20, mwidth=5)
     at what.c:82
#3 0x08049bfa in main (argc=1, argv=0xbff90cf4) at main.c:170

(gdb) bt full
#0 0xb7f0e72a in G_get_raster_cat (rast=0x80598f0, pcats=0x8051b68,
data_type=2)
     at cats.c:673
         f = 0x8051d46 ""
         l = 0xbff909c8 "è\nù¿£¬\004\bð\230\005\bh\033\005\bl"
         v = 0xb7f71090 "ZY\207\004$Â\b"
         i = -2147483648
         val = -90.842525032748952
         a = {-2.86272261e-05, -2.9214556e-05}
         fmt =
"\000\000\001\000\000\000\001\000\000\000\000\000\000\000,8ð·Õ\002\000\000\000
àï·¬8\005"
         value_str =
"\000põ·ô¿÷·\000põ·\001\000\000\000\220\tù¿ù\022÷·¬qõ·\000"
         label = '\0' <repeats 1023 times>
#1 0xb7f0e675 in G_get_d_raster_cat (rast=0x80598f0, pcats=0x8051b68) at
cats.c:636
No locals.
#2 [...]
}}}

??
Hamish

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/455&gt;
GRASS GIS <http://grass.osgeo.org>

#455: d.what.rast segfault
--------------------------+-------------------------------------------------
  Reporter: hamish | Owner: grass-dev@lists.osgeo.org
      Type: defect | Status: new
  Priority: major | Milestone: 6.4.0
Component: default | Version: unspecified
Resolution: | Keywords:
  Platform: Unspecified | Cpu: Unspecified
--------------------------+-------------------------------------------------
Comment (by hamish):

Hi,

this bug is probably related to incomplete #392 (backport
G_is_c_null_value() to devbr6).

It fails here:
{{{
#0 0xb7f0e72a in G_get_raster_cat (rast=0x80598f0, pcats=0x8051b68,
data_type=2)
     at cats.c:673
}}}

which is:
{{{
     if (!G_is_c_null_value(&i) && i < pcats->ncats) {
         if (pcats->labels[i] != NULL)
             return pcats->labels[i];
         return label;
     }
}}}

because ''i'' = -2147483648 and the pcats->labels[i] lookup fails.

So either G_quant_get_cell_value() is setting ''i'' wrong, or
G_is_c_null_value() is testing it wrong.

stepping through in the debugger shows that G_quant_get_cell_value() does
[lib/gis/quant.c:line 798]
{{{
     if (NO_EXPLICIT_RULE)
         return NO_DATA;
     if (NO_EXPLICIT_RULE)
         return NO_DATA;
}}}

(huh? why twice?)

earlier,
#define NO_DATA (G_set_c_null_value (&tmp, 1), (CELL) tmp)

and
{{{
GR6.5> r.info -t elev.sl.parm.scale
datatype=DCELL
}}}

In this case I was clicking on non-NULL data:
{{{
D0/0: G_get_raster_cat(): val 131.987214 found i -2147483648
}}}

?,
Hamish

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/455#comment:1&gt;
GRASS GIS <http://grass.osgeo.org>

#455: d.what.rast segfault
--------------------------+-------------------------------------------------
  Reporter: hamish | Owner: grass-dev@lists.osgeo.org
      Type: defect | Status: closed
  Priority: major | Milestone: 6.4.0
Component: default | Version: unspecified
Resolution: fixed | Keywords:
  Platform: Unspecified | Cpu: Unspecified
--------------------------+-------------------------------------------------
Changes (by hamish):

  * status: new => closed
  * resolution: => fixed

Comment:

appears to be fixed.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/455#comment:2&gt;
GRASS GIS <http://grass.osgeo.org>