summaryrefslogtreecommitdiffhomepage
path: root/buffer.c
diff options
context:
space:
mode:
authorMatt Johnston <matt@ucc.asn.au>2020-10-19 21:38:20 +0800
committerMatt Johnston <matt@ucc.asn.au>2020-10-19 21:38:20 +0800
commitd5cc5eb25cace6499468292e1d2c3ddb6eeac15b (patch)
tree36cce81a77285e61dc7cb5af5031f6d2bad7092e /buffer.c
parent9f642e2bd4374a45e7b828fafc11cc0d6d2b1783 (diff)
Avoid passing NULL to memcpy
Diffstat (limited to 'buffer.c')
-rw-r--r--buffer.c16
1 files changed, 1 insertions, 15 deletions
diff --git a/buffer.c b/buffer.c
index 135326f..173b8e2 100644
--- a/buffer.c
+++ b/buffer.c
@@ -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");
}