Opened 16 years ago

Closed 11 years ago

#175 closed defect (fixed)

v.to.rast labelcol= SegFaults and ignored

Reported by: hamish Owned by: grass-dev@…
Priority: normal Milestone: 6.4.3
Component: Vector Version: unspecified
Keywords: v.to.rast Cc: martinl
CPU: Unspecified Platform: Unspecified

Description

Hi,

v.to.rast segfaults with the labelcolumn= option:

#spearfish
G64> g.region -d
G64> v.to.rast in=fields out=fields.v2r labelcol=label col=cat
WARNING: Area without centroid (may be OK for island)
WARNING: Area without centroid (may be OK for island)
Converted areas: 65 of 65
Converted points/lines: 0 of 0
Segmentation fault

gdb:

#0  0xb791ef43 in strcpy () from /lib/tls/i686/cmov/libc.so.6
#1  0xb7f91793 in set_string (x=0xbf81d978, s=0x808c450 "\"NO DATA\"", copy=1)
    at string.c:108
#2  0xb7f91681 in db_set_string (x=0xbf81d978, s=0x808c450 "\"NO DATA\"")
    at string.c:39
#3  0xb7f91a1c in db_copy_string (dst=0xbf81d978, src=0x808c3a0)
    at string.c:237
#4  0xb7f9276c in db_copy_value (dst=0xbf81d968, src=0x808c390) at value.c:372
#5  0xb7efba1b in db_select_value (driver=0x808b2a0, tab=0x808af08 "fields", 
    key=0x808af18 "cat", id=0, col=0x8057d88 "label", val=0xbf81d968)
    at select.c:195
#6  0x0804c571 in update_labels (rast_name=0x8057d78 "fields.v2r", 
    vector_map=0x8057d68 "fields", field=1, label_column=0x8057d88 "label", 
    use=1, val=1, attr_column=0x8057d98 "cat") at support.c:298
#7  0x0804d369 in vect_to_rast (vector_map=0x8057d68 "fields", 
    raster_map=0x8057d78 "fields.v2r", field=1, column=0x8057d98 "cat", 
    nrows=4096, use=1, value=1, value_type=1, rgbcolumn=0x0, 
    labelcolumn=0x8057d88 "label", ftype=67) at vect2rast.c:212
#8  0x0804b1f7 in main (argc=7627107, argv=0xb79e2510) at main.c:135

Also when trying to use the vector cat for the raster cat the labelcolumn is ignored:

G64> v.to.rast in=fields out=fields.v2r labelcol=label use=cat
WARNING: Area without centroid (may be OK for island)
WARNING: Area without centroid (may be OK for island)
Converted areas: 65 of 65
Converted points/lines: 0 of 0
[success]
G64> r.category fields.v2r
1       Category 1
2       Category 2
3       Category 3
4       Category 4
5       Category 5
6       Category 6
7       Category 7
...

ie the labelcolumn= is replaced by "Category n"

G64> v.db.select fields | head
cat|label
0|"NO DATA"
1|"C. Smith #1"
2|C. Smith#2
3|P. Biggam#1
4|P. Biggam#2
5|P. Biggam#3
6|P. Biggam#5
7|P. Biggam#6
8|P. Biggam#7

?

thanks, Hamish

Change History (14)

in reply to:  description comment:1 by martinl, 16 years ago

Cc: martinl added

Replying to hamish:

v.to.rast segfaults with the labelcolumn= option:

#spearfish
G64> g.region -d
G64> v.to.rast in=fields out=fields.v2r labelcol=label col=cat
WARNING: Area without centroid (may be OK for island)
WARNING: Area without centroid (may be OK for island)
Converted areas: 65 of 65
Converted points/lines: 0 of 0
Segmentation fault

strange, I cannot reproduce segfault on my machine (GNU/Debian Unstable, 32bit, G64)

v.to.rast in=fields out=fields.v2r labelcol=label col=cat --o

r.category fields.v2r | head
1       "C. Smith #1"
2       C. Smith#2
3       P. Biggam#1
4       P. Biggam#2
5       P. Biggam#3
6       P. Biggam#5
7       P. Biggam#6
8       P. Biggam#7
9       G. Tandy#1
10      C. Mitchell#1
v.to.rast in=fields out=fields.v2r labelcol=label use=cat --o

r.category fields.v2r | head
1       Category 1
2       Category 2
3       Category 3
4       Category 4
5       Category 5
6       Category 6
7       Category 7
8       Category 8
9       Category 9
10      Category 10

Martin

comment:2 by hamish, 16 years ago

I still see it. 6.4svn, Debian/etch, 32bit P4.

Hamish

comment:3 by hamish, 16 years ago

perhaps a red herring:

in gdb frame # 2 the raster cat source string is:

  s=0x808c450 "\"NO DATA\""

note this is raster category 0. The vector map version of "fields" has a cat 0, so maybe that's legal, albeit uncommon, vector cat value.

but more to the point, this is where/why it SegFaults:

lib/db/dbmi_client/select.c

  if ( count == 0 ) db_copy_value ( val, value );
  // ie copy(destination, source)

the destination memory address (val->s->string) is out of bounds. nalloc is 48, which seems ok.

that variable is created in v.to.rast/support.c line 296 with:

dbValue value;

and then passed to db_select_value().

dbValue is defined in include/dbmi.h:

 typedef struct _db_value {
    char       isNull;
    int        i;
    double     d;
    dbString   s;
    dbDateTime t;
 } dbValue;
...
 typedef struct _db_string {
    char *string;
    int nalloc;
 } dbString;

so that dbString is being used as a target without having been malloc'd first? I am not sure where s->nalloc=48 gets set, that's a bit of a mystery to me.

Hamish

in reply to:  3 comment:4 by msieczka, 16 years ago

Replying to hamish:

note this is raster category 0. The vector map version of "fields" has a cat 0, so maybe that's > legal, albeit uncommon, vector cat value.

Sidenote - category 0 is definitely valid. Radim's words from 2006:

"'cat' 0 was introduced after v.digit and probably before QGIS-GRASS. The reason was mapping of OGR FID (which can be 0) to GRASS cat." [1]

[1]http://www.nabble.com/forum/ViewPost.jtp?post=2422467&framed=y

comment:5 by hamish, 15 years ago

CPU: Unspecified
Platform: Unspecified
Summary: v.to.rast labelcol= SegFaultv.to.rast labelcol= SegFaults and ignored

in reply to:  description comment:6 by mmetz, 15 years ago

Replying to hamish:

Hi,

v.to.rast segfaults with the labelcolumn= option:

#spearfish
G64> g.region -d
G64> v.to.rast in=fields out=fields.v2r labelcol=label col=cat
WARNING: Area without centroid (may be OK for island)
WARNING: Area without centroid (may be OK for island)
Converted areas: 65 of 65
Converted points/lines: 0 of 0
Segmentation fault

I get the segfault too with the above command, but not with

v.to.rast in=fields out=fields.v2r labelcol=label use=cat

The labels of fields.v2r are wrong, they read like

1:Category 1

Category 0 is now skipped ???

Altogether strange behaviour of v.to.rast...

I used devbr6

in reply to:  description comment:7 by martinl, 15 years ago

Replying to hamish:

> #spearfish
> G64> g.region -d
> G64> v.to.rast in=fields out=fields.v2r labelcol=label col=cat
> WARNING: Area without centroid (may be OK for island)
> WARNING: Area without centroid (may be OK for island)
> Converted areas: 65 of 65
> Converted points/lines: 0 of 0
> Segmentation fault

hopefully fixed in r39510.

Martin

comment:8 by martinl, 15 years ago

Component: defaultVector

comment:9 by neteler, 15 years ago

I can confirm that it is fixed on Ubuntu 8.04/64bit.

in reply to:  9 comment:10 by martinl, 15 years ago

Resolution: fixed
Status: newclosed

Replying to neteler:

I can confirm that it is fixed on Ubuntu 8.04/64bit.

Closing the ticket, please re-open if needed. Martin

comment:11 by hamish, 15 years ago

Priority: majornormal
Resolution: fixed
Status: closedreopened

Yes, r39510 does fix the segfault. thanks! (tested before and after svn up)

The second item: Also when trying to use the vector cat for the raster cat the labelcolumn is ignored remains unfixed, so reopening the report for that.

cheers, Hamish

in reply to:  11 comment:12 by mmetz, 12 years ago

Replying to hamish:

The second item: Also when trying to use the vector cat for the raster cat the labelcolumn is ignored remains unfixed, so reopening the report for that.

Please try trunk r51970.

Markus M

comment:13 by neteler, 12 years ago

Should this be backported?

comment:14 by hamish, 11 years ago

Milestone: 6.4.06.4.3
Resolution: fixed
Status: reopenedclosed

backported by mmetz to devbr6 and relbr64 in r52032 and r52703.

both issues tested ok in 6.4.3svn.

thanks, Hamish

Note: See TracTickets for help on using tickets.