[185] in 6.033-lab
realloc bug
daemon@ATHENA.MIT.EDU (Benjie Chen)
Tue Mar 7 22:38:19 2000
From: Benjie Chen <benjie@cag.lcs.mit.edu>
Message-Id: <200003080338.WAA20683@amsterdam.lcs.mit.edu>
To: 6.033-lab@MIT.EDU
Date: Tue, 7 Mar 2000 22:38:08 -0500 (EST)
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Hi
Yet another bug. The following changes inserted into http.c fix it. I
modified the one in the locker already.
Sorry about these bugs, I know it is a pain in the butt to work with
given src code with bugs, but hopefully there aren't anymore.
Add:
-------------
#define REALLOC_PTR(s, o, n) \
if (s != 0) s = (s - o) + n;
void
http_realloc_ptrs(HTTP m, char *oldptr, char *newptr)
{
REALLOC_PTR(m->url, oldptr, newptr);
REALLOC_PTR(m->if_modified_since, oldptr, newptr);
REALLOC_PTR(m->pragma, oldptr, newptr);
REALLOC_PTR(m->connection, oldptr, newptr);
REALLOC_PTR(m->proxy_connection, oldptr, newptr);
REALLOC_PTR(m->reason, oldptr, newptr);
REALLOC_PTR(m->date, oldptr, newptr);
REALLOC_PTR(m->expires, oldptr, newptr);
REALLOC_PTR(m->last_modified, oldptr, newptr);
REALLOC_PTR(m->data, oldptr, newptr);
}
-------------
Then changed:
m->head = xrealloc(m->head, m->len+len);
memmove(m->head+m->len, buffer, len);
m->len += len;
To:
ptr = m->head;
m->head = xrealloc(m->head, m->len+len);
memmove(m->head+m->len, buffer, len);
m->len += len;
http_realloc_ptrs(m, ptr, m->head);
The reason should be obvious if you read the code.
Benjie
--
Benjie Chen
benjie@lcs.mit.edu