Re: [Gpsbabel-code] Patch to memory allocator in Globalsat DG-100 handler, v1.3.5 (1/1)
Brought to you by:
robertl
From: Robert L. <rob...@gm...> - 2008-06-30 14:39:04
|
Applied. Thanx. On Sun, Jun 29, 2008 at 5:23 PM, Mirko Parthey < mir...@in...> wrote: > On Tue, Jun 17, 2008 at 12:35:52AM +0200, Mirko Parthey wrote: > > On Sun, Jun 15, 2008 at 09:29:00PM +0100, Stephen Goudge wrote: > > > 1) when receiving the "0 headers" a pointless call to > dynarray16_alloc() was > > > being made (pointless as the loop that followed would not be executed) > and > > > this was being passed down to realloc() which interpreted it as a > request to > > > simply de-allocate the memory. > > Thanks - I added a check to break out of the loop on "0 headers found". > > > > 2) when dynarray16_alloc() was being usefully called it was not doing > the > > > right thing: if the memory did need to be re-allocated the result from > the > > > xrealloc() was not being put into the correct place *and* a missing > test > > > before subtracting unsigned integers was causing the re-allocation to > be done > > > when it wasn't necessary. > > Thanks. > It wasn't my intention to guarantee any sort of alignment though > ("chunk" might be misleading here) - I just wanted to avoid frequent > calls to xrealloc - so I dropped those parts of your patch. > > For my version, see below - please tell me if there are any issues left. > > I'll send another patch with a few cleanups in a separate mail. > > Regards, > Mirko > > > --- dg-100.c 2008-06-29 21:19:18.000000000 +0200 > +++ dg-100.c 2008-06-29 21:05:19.000000000 +0200 > @@ -75,7 +75,6 @@ > }; > const unsigned dg100_numcommands = sizeof(dg100_commands) / > sizeof(dg100_commands[0]); > > -/* TODO: use obstacks or vmem_t instead? */ > struct dynarray16 { > unsigned count; /* number of elements used */ > unsigned limit; /* number of elements allocated */ > @@ -115,11 +114,11 @@ > i = a->count; > a->count += n; > > - need = a->count - a->limit; > - if (need > 0) { > + if (a->count > a->limit) { > + need = a->count - a->limit; > need = (need > elements_per_chunk) ? need : > elements_per_chunk; > a->limit += need; > - xrealloc(a->data, sizeof(a->data[0]) * a->limit); > + a->data = xrealloc(a->data, sizeof(a->data[0]) * a->limit); > } > return(a->data + i); > } > @@ -555,6 +554,10 @@ > nextheader = be_read16(answer + 2); > dg100_log("found %d headers, nextheader=%d\n", > numheaders, nextheader); > + if (numheaders <= 0) { > + dg100_log("no further headers, aborting the > loop\n"); > + break; > + } > > h = dynarray16_alloc(headers, numheaders); > for (i = 0; i < numheaders; i++) { > > ------------------------------------------------------------------------- > Check out the new SourceForge.net Marketplace. > It's the best place to buy or sell services for > just about anything Open Source. > http://sourceforge.net/services/buy/index.php > _______________________________________________ > Gpsbabel-code mailing list http://www.gpsbabel.org > Gps...@li... > https://lists.sourceforge.net/lists/listinfo/gpsbabel-code > |