assert (anscp != NULL || ansp2 == NULL);
thisresplenp = &resplen;
} else {
- if (*anssizp != MAXPACKET) {
+ if (*anssizp == orig_anssizp) {
/* No buffer allocated for the first
reply. We can try to use the rest
of the user-provided buffer. */
#ifdef _STRING_ARCH_unaligned
*anssizp2 = orig_anssizp - resplen;
- *ansp2 = *ansp + resplen;
+ *ansp2 = ans + resplen;
#else
int aligned_resplen
= ((resplen + __alignof__ (HEADER) - 1)
& ~(__alignof__ (HEADER) - 1));
*anssizp2 = orig_anssizp - aligned_resplen;
- *ansp2 = *ansp + aligned_resplen;
+ *ansp2 = ans + aligned_resplen;
#endif
- } else {
+ } else if (*ansp2_malloced == 0) {
/* The first reply did not fit into the
user-provided buffer. Maybe the second
answer will. */
*anssizp2 = orig_anssizp;
- *ansp2 = *ansp;
+ *ansp2 = ans;
}
thisanssizp = anssizp2;
*thisansp = newp;
if (thisansp == ansp2)
*ansp2_malloced = 1;
+ else if (thisansp == anscp)
+ *ansp = *thisansp;
anhp = (HEADER *) newp;
len = rlen;
} else {
assert (anscp != NULL || ansp2 == NULL);
thisresplenp = &resplen;
} else {
- if (*anssizp != MAXPACKET) {
+ if (*anssizp == orig_anssizp) {
/* No buffer allocated for the first
reply. We can try to use the rest
of the user-provided buffer. */
#ifdef _STRING_ARCH_unaligned
*anssizp2 = orig_anssizp - resplen;
- *ansp2 = *ansp + resplen;
+ *ansp2 = ans + resplen;
#else
int aligned_resplen
= ((resplen + __alignof__ (HEADER) - 1)
& ~(__alignof__ (HEADER) - 1));
*anssizp2 = orig_anssizp - aligned_resplen;
- *ansp2 = *ansp + aligned_resplen;
+ *ansp2 = ans + aligned_resplen;
#endif
- } else {
+ } else if (*ansp2_malloced == 0) {
/* The first reply did not fit into the
user-provided buffer. Maybe the second
answer will. */
*anssizp2 = orig_anssizp;
- *ansp2 = *ansp;
+ *ansp2 = ans;
}
thisanssizp = anssizp2;
) {
u_char *newp = malloc (MAXPACKET);
if (newp != NULL) {
- *anssizp = MAXPACKET;
- *thisansp = ans = newp;
+ *thisanssizp = MAXPACKET;
+ *thisansp = newp;
if (thisansp == ansp2)
*ansp2_malloced = 1;
+ else if (thisansp == anscp)
+ *ansp = *thisansp;
}
}
HEADER *anhp = (HEADER *) *thisansp;