[GRASS-dev] [bug #4987] (grass) malloc errors/declaration - 64
bit problems
Soeren Gebbert
soerengebbert at gmx.de
Thu Aug 10 16:42:53 EDT 2006
Hi,
On Thursday 10 August 2006 21:52, Māris Nartišs wrote:
> Hi,
>
> 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?
I think the memory allocation code is wrong.
This is a diff how it should be:
Index: main.c
===================================================================
RCS file: /home/grass/grassrepository/grass6/raster/r.lake/main.c,v
retrieving revision 1.2
diff -u -r1.2 main.c
--- main.c 13 Jun 2006 22:42:27 -0000 1.2
+++ main.c 10 Aug 2006 20:31:36 -0000
@@ -275,8 +275,8 @@
}
/* Pointers to rows. Row = ptr to 'col' size array. */
- in_terran = G_malloc(rows * sizeof(FCELL *));
- out_water = G_malloc(rows * sizeof(FCELL *));
+ in_terran = (FCELL **)G_malloc(rows * sizeof(FCELL *));
+ out_water = (FCELL **)G_malloc(rows * sizeof(FCELL *));
if (in_terran == NULL || out_water == NULL)
G_fatal_error(_("Failure to allocate memory for row pointers"));
@@ -285,8 +285,8 @@
/* foo_rows[row] == array with data (2d array). */
for (row = 0; row < rows; row++)
{
- in_terran[row] = G_malloc(cols * sizeof(FCELL *));
- out_water[row] = G_calloc(sizeof(FCELL *), cols);
+ in_terran[row] = (FCELL *)G_malloc(cols * sizeof(FCELL));
+ out_water[row] = (FCELL *)G_calloc(cols, sizeof(FCELL));
/* In newly created space load data from file.*/
if (G_get_f_raster_row(in_terran_fd, in_terran[row], row)!=1)
Best regards
Soeren
btw,:
I can submit the changes if you want.
>
> Maris.
>
> On Thursday 10 August 2006 16:54, Markus Neteler wrote:
> > On Tue, Aug 08, 2006 at 06:43:12PM +0100, Glynn Clements wrote:
> > > Request Tracker wrote:
> > > > this bug's URL: http://intevation.de/rt/webrt?serial_num=4987
> > > > Subject: malloc errors/declaration - 64 bit problems
> >
> > The modified regex from Roberto shows numerous further
> > candidates:
> >
> > egrep -R 'sizeof[ \t]*\([ \t]*[a-Z]+[ \t]*\*' . |grep [ch]: | grep -v void
> >
> > It would be good to fix at least the dangerous ones.
> >
> > Markus
> >
> > _______________________________________________
> > grass-dev mailing list
> > grass-dev at grass.itc.it
> > http://grass.itc.it/mailman/listinfo/grass-dev
>
> _______________________________________________
> grass-dev mailing list
> grass-dev at grass.itc.it
> http://grass.itc.it/mailman/listinfo/grass-dev
>
>
More information about the grass-dev
mailing list