[GRASS-dev] help with r.le.setup bug

Hi,

can one of the C gurus have a look at this?

http://thread.gmane.org/gmane.comp.gis.grass.devel/15495/focus=15598

I think it's a simple type mismatch in variables getting passed to a
function. I'd like to have r.le.* all working for 6.2.0 as it will
probably be the final time r.le.* is released.

thanks,
Hamish

Hamish wrote:

can one of the C gurus have a look at this?

http://thread.gmane.org/gmane.comp.gis.grass.devel/15495/focus=15598

I think it's a simple type mismatch in variables getting passed to a
function.

It is. ux/uy are arrays of ints but calc_unit_loc() expects arrays of
doubles.

Try the attached patch.

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

(attachments)

r.le.setup.patch (1.64 KB)

Hamish wrote:

> I think it's a simple type mismatch in variables getting passed to a
> function.

Glynn wrote:

It is. ux/uy are arrays of ints but calc_unit_loc() expects arrays of
doubles.

Try the attached patch.

[also cast to int for overlap() fn]

yes, thanks. funny, even with your patch it still messes up the "y"
values of draw_box() unless I add in the fn prototype to setup.h. Oh
well, done that and it's all working now without compiler warnings.
(and the segfault is gone)

I have also ported the r.le.setup help page from GRASS 5, fixed the
module descriptions, and sync'd all r.le changes with HEAD.

So all r.le should now be working & ready for the next release candidate.

Hamish

Hamish wrote:

> > I think it's a simple type mismatch in variables getting passed to a
> > function.

> It is. ux/uy are arrays of ints but calc_unit_loc() expects arrays of
> doubles.
>
> Try the attached patch.

[also cast to int for overlap() fn]

yes, thanks. funny, even with your patch it still messes up the "y"
values of draw_box() unless I add in the fn prototype to setup.h.

Right. overlap() expects "int"s, but some of the values passed are
changed to double by my patch. If a valid prototype is in scope, the
compiler will automatically cast them to int, otherwise it will pass
them as double.

All of those declarations in setup.h should be either fixed or
removed. If the compiler needs a prototype (because the function isn't
already in scope at the point that it's used), it needs the *correct*
prototype.

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

Glynn Clements wrote:

> > > I think it's a simple type mismatch in variables getting passed to a
> > > function.
>
> > It is. ux/uy are arrays of ints but calc_unit_loc() expects arrays of
> > doubles.
> >
> > Try the attached patch.
>
> [also cast to int for overlap() fn]
>
> yes, thanks. funny, even with your patch it still messes up the "y"
> values of draw_box() unless I add in the fn prototype to setup.h.

Right. overlap() expects "int"s, but some of the values passed are
changed to double by my patch. If a valid prototype is in scope, the
compiler will automatically cast them to int, otherwise it will pass
them as double.

All of those declarations in setup.h should be either fixed or
removed. If the compiler needs a prototype (because the function isn't
already in scope at the point that it's used), it needs the *correct*
prototype.

I've cleaned up r.le.setup. All of the functions have correct
prototypes, and any which aren't used outside of the file in which
they are defined have been declared "static". Also, I've removed the
local copy of the <dirent.h> stuff.

There is one warning which may indicate an error:

sample.c:826: warning: suggest parentheses around assignment used as truth value

which relates to:

     if (n = i % h_d)

I don't know enough about the code to determine whether this is meant
to be an assignment or a comparison.

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