[PATCH:libX11 12/12] init_om: remove unneeded extra copy of string to local buffer
Matthieu Herrb
matthieu.herrb at laas.fr
Sun Aug 11 05:35:21 PDT 2013
On Sat, Aug 10, 2013 at 01:55:09PM -0700, Alan Coopersmith wrote:
> Strings from the supported_charset_list[] were being copied one by
> one to a stack buffer, and then strdup called on that buffer.
>
> Instead, just strdup the original string, without the local copy,
> and use a more traditional for loop, so it's easier to figure out
> what the code is doing (cleaning up a gcc const-cast warning in
> the process).
>
> Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
Reviewed-by: Matthieu Herrb <matthieu.herrb at laas.fr>
> ---
> src/xlibi18n/XDefaultOMIF.c | 15 ++++-----------
> 1 file changed, 4 insertions(+), 11 deletions(-)
>
> diff --git a/src/xlibi18n/XDefaultOMIF.c b/src/xlibi18n/XDefaultOMIF.c
> index b1dc66d..596405c 100644
> --- a/src/xlibi18n/XDefaultOMIF.c
> +++ b/src/xlibi18n/XDefaultOMIF.c
> @@ -1148,10 +1148,9 @@ init_om(
> FontData font_data;
> char **required_list;
> XOrientation *orientation;
> - char **value, buf[BUFSIZ], *bufptr;
> - int count, length = 0;
> + char *bufptr;
> + int i, count, length = 0;
>
> - value = (char**)supported_charset_list;
> count = XlcNumber(supported_charset_list);
>
> data = add_data(om);
> @@ -1164,14 +1163,8 @@ init_om(
> data->font_data = font_data;
> data->font_data_count = count;
>
> - for ( ; count-- > 0; font_data++) {
> -/*
> -1266793
> -This one is fine. *value points to one of the local strings in
> -supported_charset_list[].
> -*/
> - strcpy(buf, *value++);
> - font_data->name = strdup(buf);
> + for (i = 0; i < count; i++, font_data++) {
> + font_data->name = strdup(supported_charset_list[i]);
> if (font_data->name == NULL)
> return False;
> }
> --
> 1.7.9.2
>
> _______________________________________________
> xorg-devel at lists.x.org: X.Org development
> Archives: http://lists.x.org/archives/xorg-devel
> Info: http://lists.x.org/mailman/listinfo/xorg-devel
--
Matthieu Herrb
More information about the xorg-devel
mailing list