[PATCH] [xkb] XkbWriteCountedString(): return early if str is NULL

Ian Romanick idr at freedesktop.org
Thu Dec 17 10:53:12 PST 2009


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Tomas Carnecky wrote:
> This avoids NULL from being passed to memcpy() later in the code. While
> that wasn't an issue before - that value being NULL implied 'size == 0'
> so memcpy() wouldn't try to dereference it - it made the code harder
> to read and also confused clang.
> 
> Signed-off-by: Tomas Carnecky <tom at dbservice.com>

Looks good.

Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>

> ---
>  xkb/xkb.c |    7 +++++--
>  1 files changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/xkb/xkb.c b/xkb/xkb.c
> index 98e879d..00ae29c 100644
> --- a/xkb/xkb.c
> +++ b/xkb/xkb.c
> @@ -4298,9 +4298,12 @@ ProcXkbSetNames(ClientPtr client)
>  static char *
>  XkbWriteCountedString(char *wire,char *str,Bool swap)
>  {
> -CARD16	len,*pLen;
> +    CARD16 len,*pLen;
>  
> -    len= (str?strlen(str):0);
> +    if (!str)
> +        return wire;
> +
> +    len= strlen(str);
>      pLen= (CARD16 *)wire;
>      *pLen= len;
>      if (swap) {

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAksqfhcACgkQX1gOwKyEAw/SpACglratx2zagRlR735LPgv/44xw
YUIAn2W9xpZCHFsR6iTlBbSyl/KxZtaR
=VYYe
-----END PGP SIGNATURE-----


More information about the xorg-devel mailing list