auth: use snprintf() return value

That save us from a strlen().

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2009-04-07 11:55:30 +02:00
parent 9f24c91f91
commit f0b2981974
2 changed files with 11 additions and 2 deletions

View File

@ -97,6 +97,7 @@ 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 dispbuflen;
family = FamilyLocal; /* 256 */
switch(sockname->sa_family)
@ -127,7 +128,11 @@ static Xauth *get_authptr(struct sockaddr *sockname, unsigned int socknamelen,
return 0; /* cannot authenticate this family */
}
snprintf(dispbuf, sizeof(dispbuf), "%d", display);
dispbuflen = snprintf(dispbuf, sizeof(dispbuf), "%d", display);
if(dispbuflen < 0)
return 0;
/* snprintf may have truncate our text */
dispbuflen = MIN(dispbuflen, sizeof(dispbuf) - 1);
if (family == FamilyLocal) {
if (gethostname(hostnamebuf, sizeof(hostnamebuf)) == -1)
@ -138,7 +143,7 @@ static Xauth *get_authptr(struct sockaddr *sockname, unsigned int socknamelen,
return XauGetBestAuthByAddr (family,
(unsigned short) addrlen, addr,
(unsigned short) strlen(dispbuf), dispbuf,
(unsigned short) dispbuflen, dispbuf,
N_AUTH_PROTOS, authnames, authnameslen);
}

View File

@ -60,6 +60,10 @@ enum lazy_reply_tag
#define offsetof(type,member) ((size_t) &((type *)0)->member)
#endif
#ifndef MIN
#define MIN(x,y) ((x) < (y) ? (x) : (y))
#endif
#define container_of(pointer,type,member) ((type *)(((char *)(pointer)) - offsetof(type, member)))
/* xcb_list.c */