=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/ssh/Attic/buffer.c,v retrieving revision 1.16 retrieving revision 1.16.4.3 diff -u -r1.16 -r1.16.4.3 --- src/usr.bin/ssh/Attic/buffer.c 2002/06/26 08:54:18 1.16 +++ src/usr.bin/ssh/Attic/buffer.c 2004/03/04 18:18:15 1.16.4.3 @@ -12,7 +12,7 @@ */ #include "includes.h" -RCSID("$OpenBSD: buffer.c,v 1.16 2002/06/26 08:54:18 markus Exp $"); +RCSID("$OpenBSD: buffer.c,v 1.16.4.3 2004/03/04 18:18:15 brad Exp $"); #include "xmalloc.h" #include "buffer.h" @@ -23,8 +23,11 @@ void buffer_init(Buffer *buffer) { - buffer->alloc = 4096; - buffer->buf = xmalloc(buffer->alloc); + const u_int len = 4096; + + buffer->alloc = 0; + buffer->buf = xmalloc(len); + buffer->alloc = len; buffer->offset = 0; buffer->end = 0; } @@ -34,8 +37,11 @@ void buffer_free(Buffer *buffer) { - memset(buffer->buf, 0, buffer->alloc); - xfree(buffer->buf); + if (buffer->alloc > 0) { + memset(buffer->buf, 0, buffer->alloc); + buffer->alloc = 0; + xfree(buffer->buf); + } } /* @@ -69,6 +75,7 @@ void * buffer_append_space(Buffer *buffer, u_int len) { + u_int newlen; void *p; if (len > 0x100000) @@ -98,11 +105,13 @@ goto restart; } /* Increase the size of the buffer and retry. */ - buffer->alloc += len + 32768; - if (buffer->alloc > 0xa00000) + + newlen = buffer->alloc + len + 32768; + if (newlen > 0xa00000) fatal("buffer_append_space: alloc %u not supported", - buffer->alloc); - buffer->buf = xrealloc(buffer->buf, buffer->alloc); + newlen); + buffer->buf = xrealloc(buffer->buf, newlen); + buffer->alloc = newlen; goto restart; /* NOTREACHED */ } @@ -160,7 +169,7 @@ void buffer_dump(Buffer *buffer) { - int i; + u_int i; u_char *ucp = buffer->buf; for (i = buffer->offset; i < buffer->end; i++) {