mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-07-01 16:33:30 +02:00
Merge pull request #890 from ygj6/c_master
check null pointer before using memcpy()
This commit is contained in:
commit
3bb121fb8f
@ -12,6 +12,7 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -59,6 +60,7 @@ static inline void msgpack_sbuffer_free(msgpack_sbuffer* sbuf)
|
||||
static inline int msgpack_sbuffer_write(void* data, const char* buf, size_t len)
|
||||
{
|
||||
msgpack_sbuffer* sbuf = (msgpack_sbuffer*)data;
|
||||
assert(buf || len == 0);
|
||||
|
||||
if(sbuf->alloc - sbuf->size < len) {
|
||||
void* tmp;
|
||||
@ -81,8 +83,10 @@ static inline int msgpack_sbuffer_write(void* data, const char* buf, size_t len)
|
||||
sbuf->alloc = nsize;
|
||||
}
|
||||
|
||||
if(buf) {
|
||||
memcpy(sbuf->data + sbuf->size, buf, len);
|
||||
sbuf->size += len;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user