[GRASS-dev] [bug #4987] (grass) malloc errors/declaration - 64 bit problems

Paul Kelly paul-grass at stjohnspoint.co.uk
Tue Aug 8 10:45:17 EDT 2006


On Tue, 8 Aug 2006, Request Tracker wrote:

> On Tue, Aug 08, 2006 at 04:10:04PM +0200, Roberto Flor wrote:
> Here my findings on 64 bit problems:
>
> Simple, potential error on 64 bit machines, really only for float case:
>
[...]
> ./vector/v.surf.idw/main.c:    npoints_currcell = (long **)G_malloc(window.rows * sizeof(long));
>
[...]
>
> Hyper allocation, requires more memory than necessary:
>
> ./vector/v.surf.idw/main.c:        search_list = (struct cell_list **)G_malloc(max_radius * sizeof(struct cell_list));
> ./vector/v.surf.idw/main.c:        search_list_start = (struct cell_list **)G_malloc(max_radius * sizeof(struct cell_list));
> ./vector/v.surf.idw/main.c:    points = (struct Point ***)G_malloc(window.rows * sizeof(struct Point));
> ./vector/v.surf.idw/main.c:        points[row] = (struct Point **)G_malloc(window.cols * sizeof(struct Point));
>
> In all the case the sizeof shoul to be of a pointer.

The v.surf.idw are all my mistakes; well spotted and thanks for pointing 
them out. To fix them, I guess the size of a pointer is always the same no 
matter what type it points to, so is there a standard way of representing 
it always, e.g. like sizeof(char *)? Or should we always write sizeof(long *),
sizeof(struct Point *) etc. as appropriate? Is it just a question of
programming style?

Paul




More information about the grass-dev mailing list