[Xcb] [PATCH] auth: precompute authnamelens

Barton C Massey bart at cs.pdx.edu
Wed Apr 8 01:17:23 PDT 2009


The compiler may be able to precompute these anyway.  The
risk with your patch is that if someone bumps the keyboard
on one of the names, they're out of sync.  If you really
want this, define macros so that the names only have to be
entered once, I think.

	Bart

In message <1239097868-26181-1-git-send-email-julien at danjou.info> you wrote:
> Signed-off-by: Julien Danjou <julien at danjou.info>
> ---
> I think that's a better practice and that is harmless, but
> I would be really glad if someone can review this patch as it
> is very trivial.
> 
>  src/xcb_auth.c |   11 +++++++----
>  1 files changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/src/xcb_auth.c b/src/xcb_auth.c
> index 93a6f68..1645ce8 100644
> --- a/src/xcb_auth.c
> +++ b/src/xcb_auth.c
> @@ -56,6 +56,13 @@ static char *authnames[N_AUTH_PROTOS] = {
>      "MIT-MAGIC-COOKIE-1",
>  };
>  
> +static int authnamelens[N_AUTH_PROTOS] = {
> +#ifdef HASXDMAUTH
> +    sizeof("XDM-AUTHORIZATION-1") - 1,
> +#endif
> +    sizeof("MIT-MAGIC-COOKIE-1") - 1,
> +};
> +
>  static size_t memdup(char **dst, void *src, size_t len)
>  {
>      if(len)
> @@ -87,8 +94,6 @@ static Xauth *get_authptr(struct sockaddr *sockname, unsigned int socknamelen,
>      unsigned short family;
>      char hostnamebuf[256];   /* big enough for max hostname */
>      char dispbuf[40];   /* big enough to hold more than 2^64 base 10 */
> -    int authnamelens[N_AUTH_PROTOS];
> -    int i;
>  
>      family = FamilyLocal; /* 256 */
>      switch(sockname->sa_family)
> @@ -128,8 +133,6 @@ static Xauth *get_authptr(struct sockaddr *sockname, unsigned int socknamelen,
>          addrlen = strlen(addr);
>      }
>  
> -    for (i = 0; i < N_AUTH_PROTOS; i++)
> -	authnamelens[i] = strlen(authnames[i]);
>      return XauGetBestAuthByAddr (family,
>                                   (unsigned short) addrlen, addr,
>                                   (unsigned short) strlen(dispbuf), dispbuf,
> -- 
> 1.6.2.2
> 
> _______________________________________________
> Xcb mailing list
> Xcb at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/xcb


More information about the Xcb mailing list