Merge pull request #899 from redboltz/fix_buffer_ptr_size

Fix buffer ptr size
This commit is contained in:
Takatoshi Kondo
2020-07-03 19:42:50 +09:00
committed by GitHub
6 changed files with 20 additions and 7 deletions

View File

@@ -61,7 +61,7 @@ jobs:
cd ..
# build and test
CMAKE_CXX_COMPILER="${CXX}" CMAKE_C_COMPILER="${CC}" GTEST_ROOT="${BASE}/usr" CFLAGS="-Werror -g" CXXFLAGS="-Werror -g" ${ACTION}
CMAKE_CXX_COMPILER="${CXX}" CMAKE_C_COMPILER="${CC}" GTEST_ROOT="${BASE}/usr" CFLAGS="-Werror -g -fsanitize=undefined" CXXFLAGS="-Werror -g -fsanitize=undefined" ${ACTION}
linux:
runs-on: ubuntu-18.04
@@ -172,7 +172,7 @@ jobs:
fi
# build and test
CMAKE_CXX_COMPILER="${CXX}" CMAKE_C_COMPILER="${CC}" GTEST_ROOT="${BASE}/usr" CFLAGS="-Werror -g" CXXFLAGS="-Werror -g" MSGPACK_SAN="${SAN}" ${ACTION}
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}
windows:
runs-on: windows-2019

View File

@@ -25,7 +25,7 @@ else
export ARCH_FLAG="-m64"
fi
cmake -DMSGPACK_32BIT=${BIT32} -DBUILD_SHARED_LIBS=${SHARED} -DMSGPACK_CHAR_SIGN=${CHAR_SIGN} -DCMAKE_CXX_FLAGS=${ARCH_FLAG} ..
cmake -DMSGPACK_32BIT=${BIT32} -DBUILD_SHARED_LIBS=${SHARED} -DMSGPACK_CHAR_SIGN=${CHAR_SIGN} -DCMAKE_CXX_FLAGS="${ARCH_FLAG} ${CXXFLAGS}" -DCMAKE_C_FLAGS="${CFLAGS}" ..
ret=$?
if [ $ret -ne 0 ]

View File

@@ -11,6 +11,7 @@
#define MSGPACK_FBUFFER_H
#include <stdio.h>
#include <assert.h>
#ifdef __cplusplus
extern "C" {
@@ -25,6 +26,9 @@ extern "C" {
static inline int msgpack_fbuffer_write(void* data, const char* buf, size_t len)
{
assert(buf || len == 0);
if(!buf) return 0;
return (1 == fwrite(buf, len, 1, (FILE *)data)) ? 0 : -1;
}

View File

@@ -60,7 +60,9 @@ 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(!buf) return 0;
if(sbuf->alloc - sbuf->size < len) {
void* tmp;
@@ -83,10 +85,9 @@ 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;
}
memcpy(sbuf->data + sbuf->size, buf, len);
sbuf->size += len;
return 0;
}

View File

@@ -12,6 +12,7 @@
#include "zone.h"
#include <stdlib.h>
#include <assert.h>
#if defined(unix) || defined(__unix) || defined(__linux__) || defined(__APPLE__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__QNX__) || defined(__QNXTO__) || defined(__HAIKU__)
#include <sys/uio.h>
@@ -114,6 +115,9 @@ static inline void msgpack_vrefbuffer_free(msgpack_vrefbuffer* vbuf)
static inline int msgpack_vrefbuffer_write(void* data, const char* buf, size_t len)
{
msgpack_vrefbuffer* vbuf = (msgpack_vrefbuffer*)data;
assert(buf || len == 0);
if(!buf) return 0;
if(len < vbuf->ref_size) {
return msgpack_vrefbuffer_append_copy(vbuf, buf, len);

View File

@@ -13,6 +13,7 @@
#include "sysdep.h"
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <zlib.h>
#ifdef __cplusplus
@@ -121,6 +122,9 @@ static inline int msgpack_zbuffer_write(void* data, const char* buf, size_t len)
{
msgpack_zbuffer* zbuf = (msgpack_zbuffer*)data;
assert(buf || len == 0);
if(!buf) return 0;
zbuf->stream.next_in = (Bytef*)buf;
zbuf->stream.avail_in = (uInt)len;