Fix some memory corruption bugs in the dynamic list resizing code.

This commit is contained in:
Laurence Withers 2007-01-09 14:02:09 +00:00
parent ad6f784731
commit 372e355a73
1 changed files with 4 additions and 3 deletions

View File

@ -55,14 +55,15 @@ static int do_realloc2(struct csxml* ctx, struct csxml_list* list)
{
size_t i, newlen = list->size ? (list->size << 1) : 4;
struct csxml_buf* n = realloc(list->data, newlen * sizeof(struct csxml_buf));
if(!n) {
ctx->outOfMemory(ctx, newlen * sizeof(struct csxml_buf));
return -1;
}
memset(n + list->size * sizeof(struct csxml_buf), 0, newlen * sizeof(struct csxml_buf));
for(i = 0; i < newlen; ++i) {
if(buffer_init(ctx, n + list->size + i)) return -1;
memset(n + list->size, 0, (newlen - list->size) * sizeof(struct csxml_buf));
for(i = list->size; i < newlen; ++i) {
if(buffer_init(ctx, n + i)) return -1;
}
list->size = newlen;