[GRASS-dev] [bug #4987] (grass) malloc errors/declaration - 64
bit problems
Glynn Clements
glynn at gclements.plus.com
Thu Aug 10 17:53:04 EDT 2006
M-Dàris Narti-B¹s wrote:-A
> my C skills are too poor to understand it.
>
> Modified regex poped up also
> ./raster/r.lake/main.c: in_terran = G_malloc(rows * sizeof(FCELL *));
>
> So - in brief- how it should look to be correct and safe?
That one is correct. The type passed to sizeof() should have one less
"*" than the type of the data being allocated. E.g. in_terran has type
FCELL** so the allocation multiple should be FCELL*, which is what is
used.
However, further down in that file, we have:
in_terran[row] = G_malloc(cols * sizeof(FCELL *));
in_terran is FCELL**, so in_terran[row] is FCELL*, so the allocation
multiple should be just FCELL. Ditto for out_water.
There's no way that this kind of error can reliably be detected by a
regex. The correct type depends upon the type of the lvalue to which
the result is assigned, and that can't be determined by a regex.
--
Glynn Clements <glynn at gclements.plus.com>
More information about the grass-dev
mailing list