mirror of
https://github.com/clearml/dropbear
synced 2025-05-05 20:44:33 +00:00
Avoid passing NULL to memcpy
This commit is contained in:
parent
9f642e2bd4
commit
d5cc5eb25c
14
buffer.c
14
buffer.c
@ -39,44 +39,30 @@
|
|||||||
|
|
||||||
/* Create (malloc) a new buffer of size */
|
/* Create (malloc) a new buffer of size */
|
||||||
buffer* buf_new(unsigned int size) {
|
buffer* buf_new(unsigned int size) {
|
||||||
|
|
||||||
buffer* buf;
|
buffer* buf;
|
||||||
|
|
||||||
if (size > BUF_MAX_SIZE) {
|
if (size > BUF_MAX_SIZE) {
|
||||||
dropbear_exit("buf->size too big");
|
dropbear_exit("buf->size too big");
|
||||||
}
|
}
|
||||||
|
|
||||||
buf = (buffer*)m_malloc(sizeof(buffer)+size);
|
buf = (buffer*)m_malloc(sizeof(buffer)+size);
|
||||||
|
|
||||||
if (size > 0) {
|
|
||||||
buf->data = (unsigned char*)buf + sizeof(buffer);
|
buf->data = (unsigned char*)buf + sizeof(buffer);
|
||||||
} else {
|
|
||||||
buf->data = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
buf->size = size;
|
buf->size = size;
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* free the buffer's data and the buffer itself */
|
/* free the buffer's data and the buffer itself */
|
||||||
void buf_free(buffer* buf) {
|
void buf_free(buffer* buf) {
|
||||||
|
|
||||||
m_free(buf);
|
m_free(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* overwrite the contents of the buffer to clear it */
|
/* overwrite the contents of the buffer to clear it */
|
||||||
void buf_burn(const buffer* buf) {
|
void buf_burn(const buffer* buf) {
|
||||||
|
|
||||||
m_burn(buf->data, buf->size);
|
m_burn(buf->data, buf->size);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* resize a buffer, pos and len will be repositioned if required when
|
/* resize a buffer, pos and len will be repositioned if required when
|
||||||
* downsizing */
|
* downsizing */
|
||||||
buffer* buf_resize(buffer *buf, unsigned int newsize) {
|
buffer* buf_resize(buffer *buf, unsigned int newsize) {
|
||||||
|
|
||||||
if (newsize > BUF_MAX_SIZE) {
|
if (newsize > BUF_MAX_SIZE) {
|
||||||
dropbear_exit("buf->size too big");
|
dropbear_exit("buf->size too big");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user