1
0
mirror of https://github.com/moparisthebest/curl synced 2024-11-15 22:15:13 -05:00

fix compiler warning

This commit is contained in:
Yang Tse 2010-02-23 18:46:27 +00:00
parent 4186b5b41f
commit aa0f8593b9
2 changed files with 19 additions and 11 deletions

View File

@ -69,17 +69,21 @@ int ares_expand_name(const unsigned char *encoded, const unsigned char *abuf,
int len, indir = 0; int len, indir = 0;
char *q; char *q;
const unsigned char *p; const unsigned char *p;
union {
ssize_t sig;
size_t uns;
} nlen;
len = name_length(encoded, abuf, alen); nlen.sig = name_length(encoded, abuf, alen);
if (len < 0) if (nlen.sig < 0)
return ARES_EBADNAME; return ARES_EBADNAME;
*s = malloc(((size_t)len) + 1); *s = malloc(nlen.uns + 1);
if (!*s) if (!*s)
return ARES_ENOMEM; return ARES_ENOMEM;
q = *s; q = *s;
if (len == 0) { if (nlen.uns == 0) {
/* RFC2181 says this should be ".": the root of the DNS tree. /* RFC2181 says this should be ".": the root of the DNS tree.
* Since this function strips trailing dots though, it becomes "" * Since this function strips trailing dots though, it becomes ""
*/ */

View File

@ -46,26 +46,30 @@ int ares_expand_string(const unsigned char *encoded,
long *enclen) long *enclen)
{ {
unsigned char *q; unsigned char *q;
long len; union {
ssize_t sig;
size_t uns;
} elen;
if (encoded == abuf+alen) if (encoded == abuf+alen)
return ARES_EBADSTR; return ARES_EBADSTR;
len = *encoded; elen.uns = *encoded;
if (encoded+len+1 > abuf+alen) if (encoded+elen.sig+1 > abuf+alen)
return ARES_EBADSTR; return ARES_EBADSTR;
encoded++; encoded++;
*s = malloc(len+1); *s = malloc(elen.uns+1);
if (*s == NULL) if (*s == NULL)
return ARES_ENOMEM; return ARES_ENOMEM;
q = *s; q = *s;
strncpy((char *)q, (char *)encoded, len); strncpy((char *)q, (char *)encoded, elen.uns);
q[len] = '\0'; q[elen.uns] = '\0';
*s = q; *s = q;
*enclen = len+1; *enclen = (long)(elen.sig+1);
return ARES_SUCCESS; return ARES_SUCCESS;
} }