Skip to content

Commit 4f59b98

Browse files
authored
Merge pull request #899 from redboltz/fix_buffer_ptr_size
Fix buffer ptr size
2 parents 3bb121f + 208ec65 commit 4f59b98

6 files changed

Lines changed: 20 additions & 7 deletions

File tree

.github/workflows/gha.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ jobs:
6161
cd ..
6262
6363
# build and test
64-
CMAKE_CXX_COMPILER="${CXX}" CMAKE_C_COMPILER="${CC}" GTEST_ROOT="${BASE}/usr" CFLAGS="-Werror -g" CXXFLAGS="-Werror -g" ${ACTION}
64+
CMAKE_CXX_COMPILER="${CXX}" CMAKE_C_COMPILER="${CC}" GTEST_ROOT="${BASE}/usr" CFLAGS="-Werror -g -fsanitize=undefined" CXXFLAGS="-Werror -g -fsanitize=undefined" ${ACTION}
6565
6666
linux:
6767
runs-on: ubuntu-18.04
@@ -172,7 +172,7 @@ jobs:
172172
fi
173173
174174
# build and test
175-
CMAKE_CXX_COMPILER="${CXX}" CMAKE_C_COMPILER="${CC}" GTEST_ROOT="${BASE}/usr" CFLAGS="-Werror -g" CXXFLAGS="-Werror -g" MSGPACK_SAN="${SAN}" ${ACTION}
175+
CMAKE_CXX_COMPILER="${CXX}" CMAKE_C_COMPILER="${CC}" GTEST_ROOT="${BASE}/usr" CFLAGS="-Werror -g -fsanitize=undefined" CXXFLAGS="-Werror -g -fsanitize=undefined" MSGPACK_SAN="${SAN}" ${ACTION}
176176
177177
windows:
178178
runs-on: windows-2019

ci/build_cmake.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ else
2525
export ARCH_FLAG="-m64"
2626
fi
2727

28-
cmake -DMSGPACK_32BIT=${BIT32} -DBUILD_SHARED_LIBS=${SHARED} -DMSGPACK_CHAR_SIGN=${CHAR_SIGN} -DCMAKE_CXX_FLAGS=${ARCH_FLAG} ..
28+
cmake -DMSGPACK_32BIT=${BIT32} -DBUILD_SHARED_LIBS=${SHARED} -DMSGPACK_CHAR_SIGN=${CHAR_SIGN} -DCMAKE_CXX_FLAGS="${ARCH_FLAG} ${CXXFLAGS}" -DCMAKE_C_FLAGS="${CFLAGS}" ..
2929

3030
ret=$?
3131
if [ $ret -ne 0 ]

include/msgpack/fbuffer.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#define MSGPACK_FBUFFER_H
1212

1313
#include <stdio.h>
14+
#include <assert.h>
1415

1516
#ifdef __cplusplus
1617
extern "C" {
@@ -25,6 +26,9 @@ extern "C" {
2526

2627
static inline int msgpack_fbuffer_write(void* data, const char* buf, size_t len)
2728
{
29+
assert(buf || len == 0);
30+
if(!buf) return 0;
31+
2832
return (1 == fwrite(buf, len, 1, (FILE *)data)) ? 0 : -1;
2933
}
3034

include/msgpack/sbuffer.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ static inline void msgpack_sbuffer_free(msgpack_sbuffer* sbuf)
6060
static inline int msgpack_sbuffer_write(void* data, const char* buf, size_t len)
6161
{
6262
msgpack_sbuffer* sbuf = (msgpack_sbuffer*)data;
63+
6364
assert(buf || len == 0);
65+
if(!buf) return 0;
6466

6567
if(sbuf->alloc - sbuf->size < len) {
6668
void* tmp;
@@ -83,10 +85,9 @@ static inline int msgpack_sbuffer_write(void* data, const char* buf, size_t len)
8385
sbuf->alloc = nsize;
8486
}
8587

86-
if(buf) {
87-
memcpy(sbuf->data + sbuf->size, buf, len);
88-
sbuf->size += len;
89-
}
88+
memcpy(sbuf->data + sbuf->size, buf, len);
89+
sbuf->size += len;
90+
9091
return 0;
9192
}
9293

include/msgpack/vrefbuffer.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "zone.h"
1414
#include <stdlib.h>
15+
#include <assert.h>
1516

1617
#if defined(unix) || defined(__unix) || defined(__linux__) || defined(__APPLE__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__QNX__) || defined(__QNXTO__) || defined(__HAIKU__)
1718
#include <sys/uio.h>
@@ -114,6 +115,9 @@ static inline void msgpack_vrefbuffer_free(msgpack_vrefbuffer* vbuf)
114115
static inline int msgpack_vrefbuffer_write(void* data, const char* buf, size_t len)
115116
{
116117
msgpack_vrefbuffer* vbuf = (msgpack_vrefbuffer*)data;
118+
assert(buf || len == 0);
119+
120+
if(!buf) return 0;
117121

118122
if(len < vbuf->ref_size) {
119123
return msgpack_vrefbuffer_append_copy(vbuf, buf, len);

include/msgpack/zbuffer.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "sysdep.h"
1414
#include <stdlib.h>
1515
#include <string.h>
16+
#include <assert.h>
1617
#include <zlib.h>
1718

1819
#ifdef __cplusplus
@@ -121,6 +122,9 @@ static inline int msgpack_zbuffer_write(void* data, const char* buf, size_t len)
121122
{
122123
msgpack_zbuffer* zbuf = (msgpack_zbuffer*)data;
123124

125+
assert(buf || len == 0);
126+
if(!buf) return 0;
127+
124128
zbuf->stream.next_in = (Bytef*)buf;
125129
zbuf->stream.avail_in = (uInt)len;
126130

0 commit comments

Comments
 (0)