[GRASS-dev] r.fuzzy.system can someone check???
Markus Metz
markus.metz.giswork at googlemail.com
Mon Apr 26 03:19:07 EDT 2010
On Sat, Apr 24, 2010 at 7:45 AM, Jarek Jasiewicz <jarekj at amu.edu.pl> wrote:
> Maris Nartiss pisze:
>
> Hello,
>> this module was running just fine on my ~AMD64 Gentoo, still Valgrind
>> was complaining a bit (no idea if it's harmfull in Your code):
>> Calculate...
>> 0% ==28214== Invalid read of size 4
>> ==28214== at 0x402388: fuzzy (fuzzylogic.c:8)
>> ==28214== by 0x405055: implicate (system.c:41)
>> ==28214== by 0x4034C4: main (main.c:186)
>> ==28214== Address 0x5e8e360 is not stack'd, malloc'd or (recently) free'd
>> ==28214==
>> ==28214== Invalid read of size 4
>> ==28214== at 0x402393: fuzzy (fuzzylogic.c:10)
>> ==28214== by 0x405055: implicate (system.c:41)
>> ==28214== by 0x4034C4: main (main.c:186)
>> ==28214== Address 0x5e8e364 is not stack'd, malloc'd or (recently) free'd
>> ==28214==
>> 16% 33% 50% 66% 83% 100% Close...
>>
>>
>> Maris.
>>
>>
> Thanks Maris,
> this is that which cause segment fault 32 bit, thanks very much
> The problem Is I do not know how to fix it....
>
I have some suggestions but don't know if these would fix it.
I could not find where you allocate memory for s_maps[output_index].sets,
only for sets in input maps. Maybe it's worth to add some more debug
statements and checks? Init sets to NULL, then if(s_maps[output_index].sets)
G_fatal_error("Oops forgot sets"); then you would know what to fix.
Fixing compiler warnings (the line numbers refer to the formatted version in
svn):
fuzzylogic.c:86:
return (x == y == 0) ? 0 : (x * y) / ((x + y) - x * y);
rather
return (x == 0 || y == 0) ? 0 : (x * y) / ((x + y) - x * y);
x == y == 0 is nonsense anyway
helpers.c:35
for (a = b = buf; *a == rem || *a == ' ' || *a == ' \t'; a++) ;
must be
for (a = b = buf; *a == rem || *a == ' ' || *a == '\t'; a++) ;
io.c: function ‘create_output_maps’:
add
return 1;
or make it
void create_output_maps(void)
local_proto.h:175
add
int get_cells(int col);
system.c:67
/* -- -- -- -- -- -- -- --
must be
/* -- -- -- -- -- -- -- -- */
system.c:142
add
default:
break;
system.c function
float parse_expression(int n)
has no return value
system.c:41
consequent = fuzzy(universe[i],
&s_maps[output_index].sets[set_index]);
set_index = s_rules[j].output_set_index;
should rather be
set_index = s_rules[j].output_set_index;
consequent = fuzzy(universe[i],
&s_maps[output_index].sets[set_index]);
or put
set_index = s_rules[j].output_set_index;
just before
for (i = 0; i < resolution; ++i) {
The code would be somewhat easier to read if variables would not have the
same name like custom typedefs, e.g. typedef struct map and char map[30].
HTH,
Markus
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/grass-dev/attachments/20100426/1f2c72e0/attachment.html
More information about the grass-dev
mailing list