Commit edd82a96 authored by Vasil Velichkov's avatar Vasil Velichkov Committed by Lev Walkin

Do not call memcpy with NULL src pointer

This fix the following ubsan error
check-62.c:36:2: runtime error: null pointer passed as argument 2, which is declared to never be null
parent fc25d5e7
......@@ -80,7 +80,9 @@ xer__buffer_append(const void *buffer, size_t size, void *app_key) {
size_t new_size = 2 * (xb->allocated_size ? xb->allocated_size : 64);
char *new_buf = MALLOC(new_size);
if(!new_buf) return -1;
memcpy(new_buf, xb->buffer, xb->buffer_size);
if (xb->buffer) {
memcpy(new_buf, xb->buffer, xb->buffer_size);
}
FREEMEM(xb->buffer);
xb->buffer = new_buf;
xb->allocated_size = new_size;
......
......@@ -17,7 +17,9 @@ _buf_writer(const void *buffer, size_t size, void *app_key) {
unsigned char *b, *bend;
(void)app_key;
assert(buf_offset + size < sizeof(buf));
memcpy(buf + buf_offset, buffer, size);
if (buffer) {
memcpy(buf + buf_offset, buffer, size);
}
b = buf + buf_offset;
bend = b + size;
printf("=> [");
......
......@@ -33,7 +33,9 @@ _buf_writer(const void *buffer, size_t size, void *app_key) {
unsigned char *b, *bend;
(void)app_key;
assert(buf_offset + size < sizeof(buf));
memcpy(buf + buf_offset, buffer, size);
if (buffer) {
memcpy(buf + buf_offset, buffer, size);
}
b = buf + buf_offset;
bend = b + size;
printf("=> [");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment