Re: gstring.c tweaks



On 13 Feb 2000, Havoc Pennington wrote:

> Tim Janik <timj@gtk.org> writes:
> > >    g_return_val_if_fail (string != NULL, NULL);
> > >    g_return_val_if_fail (val != NULL, fstring);
> > > +  g_return_val_if_fail (pos <= string->len, fstring);
> > 
> > why did you get rid of this g_return_val_if_fail() statement?
> > what happens if pos > string->len? how would that be usefull?
> > 
> 
> Didn't I add one here?

yes sorry, must have misread the patch.

> > > -  g_return_val_if_fail (string != NULL, NULL);
> > > -  g_string_maybe_expand (string, 1);
> > > +  return g_string_insert_len(fstring, -1, val, -1);
> > > +}
> > 
> > keep the g_return_val_if_fail() statements.
> >
> 
> This one is now in g_string_insert_len(), do you want it to run twice?
> I guess that makes the warning somewhat simpler to understand.

yes, if the user calls g_string_append(), better make that function
appear in the warning as well. besides that, code is easily changed
to contain gstring->len and similar statements in such "wrapper"
functions, which will lead to segmentation faults if the asertments
aren't kept in place (we've had that a couple of times already).
!= NULL assertements are extremely cheap, so i wouldn't bother about
it getting run twice, if you feel strongly about the double checks
though, you can always make an inlined g_string_insert_len_internal()
that comes without the checks, and simply call that from the exported
functions.

> 
> Havoc
> 

---
ciaoTJ



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]