# HG changeset patch # User Matt Johnston # Date 1603114700 -28800 # Node ID ff51d5967e2dd579b9f5f2b8db96270c35c4ac5e # Parent 28ab2cdb84bf4951cded1bde4927ab949a7cc0bd Avoid passing NULL to memcpy diff -r 28ab2cdb84bf -r ff51d5967e2d buffer.c --- a/buffer.c Sun Oct 18 23:32:39 2020 +0800 +++ b/buffer.c Mon Oct 19 21:38:20 2020 +0800 @@ -39,44 +39,30 @@ /* Create (malloc) a new buffer of size */ buffer* buf_new(unsigned int size) { - buffer* buf; - if (size > BUF_MAX_SIZE) { dropbear_exit("buf->size too big"); } buf = (buffer*)m_malloc(sizeof(buffer)+size); - - if (size > 0) { - buf->data = (unsigned char*)buf + sizeof(buffer); - } else { - buf->data = NULL; - } - + buf->data = (unsigned char*)buf + sizeof(buffer); buf->size = size; - return buf; - } /* free the buffer's data and the buffer itself */ void buf_free(buffer* buf) { - m_free(buf); } /* overwrite the contents of the buffer to clear it */ void buf_burn(const buffer* buf) { - m_burn(buf->data, buf->size); - } /* resize a buffer, pos and len will be repositioned if required when * downsizing */ buffer* buf_resize(buffer *buf, unsigned int newsize) { - if (newsize > BUF_MAX_SIZE) { dropbear_exit("buf->size too big"); }