[systemd-devel] [PATCH] localed: validate set-x11-keymap input

Lennart Poettering lennart at poettering.net
Tue Nov 11 04:48:36 PST 2014


On Tue, 11.11.14 13:34, Jan Synacek (jsynacek at redhat.com) wrote:

> >> +                r = strv_extend(list, l);
> >> +                if (r < 0)
> >> +                        return log_oom();
> >
> > I think, while we are at it, this should really be reworked to use
> > GREEDY_REALLOC. See strv_split_quoted() for an example.
> 
> Could you please explain why? str_extend() uses realloc_multiply()
> inside, which, to me, seems to be ok for this case.

strv_extend() increases the size of the strv
one-by-one. GREEDY_REALLOC grows the array exponentially. Given that
you use strv_extend() here to add quite a number of entries to the
array it is hence a good idea to make use of GREEDY_REALLOC in favour
of strv_extend().

strv_extend() is really something to avoid unless you know the number
of entries stays low. If the strv might grow to more than a handful of
entries it's a wise idea to use GREEDY_REALLOC instead.

Lennart

-- 
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list