You are not logged in.

#1 2008-03-16 17:29:26

neok
Member
From: Cyprus
Registered: 2003-12-14
Posts: 190
Website

Baffled by a strange bug - please help!!!

Hi all,

I am baffled by a bug in a program I am working on that I just
can't understand. Here is the code that causes a SIGSEGV crash:

268      int k = wfall_pixbuf.rowstride;
269      pix[0] = pix[ -k ];
270      pix[0] = pix[ -wfall_pixbuf.rowstride ];

Output of gdb:
Program received signal SIGSEGV, Segmentation fault.
0x00000000004152b2 in Display_Waterfall () at display.c:270
270          pix[0] = pix[ -wfall_pixbuf.rowstride];

wfall_pixbuf is a struct that encapsulates a GdkPixbuf together
with some variables that hold the values of some properties like
rowstride above.

I added lines 268 and 269 in despair and the program
works well if I comment out line 270, which does (I think)
the same job as 269. I can't see how wfall_pixbuf.rowstride
can change value from line 268 to 270???

Please help!!!


Regards

Neoklis ... Ham Radio Call: 5B4AZ

Offline

#2 2008-03-16 17:45:35

danielsoft
Member
From: Czech Republic
Registered: 2008-02-16
Posts: 102

Re: Baffled by a strange bug - please help!!!

hello,
I think it's a type issue: what type is wfall_pixbuf.rowstride ?
in the case

int k = wfall_pixbuf.rowstride;
pix[0] = pix[ -k ];

you are making a negative value out of type "int" - precisely signed int
when wfall_pixbuf.rowstride is unsigned, the result is undefined...

what does

pix[0] = pix[ -(int)wfall_pixbuf.rowstride ];

do? should work the same as lines 268 and 269

Last edited by danielsoft (2008-03-16 17:46:00)


may the Source be with you

Offline

#3 2008-03-16 17:52:02

danielsoft
Member
From: Czech Republic
Registered: 2008-02-16
Posts: 102

Re: Baffled by a strange bug - please help!!!

(in fact, it need not to be signed/unsigned issue, when the type of wfall_pixbuf.rowstride is something like short or char, this can also be considered the cause... I can only guess, because I don't know the type, but it's the only thing that is different in lines 268 269 versus line 270 )


may the Source be with you

Offline

#4 2008-03-16 18:03:31

neok
Member
From: Cyprus
Registered: 2003-12-14
Posts: 190
Website

Re: Baffled by a strange bug - please help!!!

danielsoft wrote:

hello,
I think it's a type issue: what type is wfall_pixbuf.rowstride ?
in the case

int k = wfall_pixbuf.rowstride;
pix[0] = pix[ -k ];

you are making a negative value out of type "int" - precisely signed int
when wfall_pixbuf.rowstride is unsigned, the result is undefined...

what does

pix[0] = pix[ -(int)wfall_pixbuf.rowstride ];

do? should work the same as lines 268 and 269

Ahh, thank you very much! rowstride is of type guint, which is
a GTK2 type definition, essentially I think it boils down to
unsigned int. So that was the issue :-)

I am surprised that I didn't make a mistake of this sort till now
but its never too late.... ;-)


Regards

Neoklis ... Ham Radio Call: 5B4AZ

Offline

#5 2008-03-16 20:55:17

kumico
Member
Registered: 2007-09-28
Posts: 224
Website

Re: Baffled by a strange bug - please help!!!

guint aka unsigned int is from GLib, i think i personally find it worthwhile to use the the glib typenames, gint, guint, gchar, etc.
it helps against making mistakes like these.
http://library.gnome.org/devel/glib/stable/

Last edited by kumico (2008-03-16 20:55:46)

Offline

Board footer

Powered by FluxBB