Update vendored msgpack-c to 4.0.0
authorMichael Jeanson <mjeanson@efficios.com>
Thu, 24 Mar 2022 18:29:36 +0000 (14:29 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 25 Mar 2022 19:58:13 +0000 (15:58 -0400)
The upstream changes from 3.3.0 to 4.0.0 :

  * Fix and improve alignment logic (#962)
  * Fix iovec name conflict (#953)
  * Fix empty string print (#942)
  * Fix buffer ptr size (#899)
  * Fix UB. Check null pointer before using memcpy() (#890)

Change-Id: Ifc4d7de43d0f11d6331d98d7cfa93227f8b756bc
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
13 files changed:
src/vendor/msgpack/Makefile.am
src/vendor/msgpack/fbuffer.h
src/vendor/msgpack/lttng-config.h
src/vendor/msgpack/objectc.c
src/vendor/msgpack/pack_template.h
src/vendor/msgpack/predef.h [deleted file]
src/vendor/msgpack/sbuffer.h
src/vendor/msgpack/sysdep.h
src/vendor/msgpack/version_master.h
src/vendor/msgpack/vrefbuffer.c
src/vendor/msgpack/vrefbuffer.h
src/vendor/msgpack/zbuffer.h
src/vendor/msgpack/zone.h

index 6666b6108c108c39fd423a8f4f51ec9cd3d55ee7..7ad4f667111860b8137b9384cea790d8786252a6 100644 (file)
@@ -16,7 +16,6 @@ libmsgpack_la_SOURCES = \
        pack_define.h \
        pack.h \
        pack_template.h \
-       predef.h \
        sbuffer.h \
        sysdep.h \
        timestamp.h \
index d478008c8d65b72484aeba5ac93e9804fe9aef35..5c847dd97b32c6740c9b4efe67f794145439cd28 100644 (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;
 }
 
index 54b14682e4f24419d67faa0201171a0673aea052..d2f49b281ed4226e1e26d1391a974990e558dc3c 100644 (file)
@@ -13,7 +13,9 @@
 
 #if BYTE_ORDER == LITTLE_ENDIAN
 #define MSGPACK_ENDIAN_LITTLE_BYTE 1
+#define MSGPACK_ENDIAN_BIG_BYTE 0
 #elif BYTE_ORDER == BIG_ENDIAN
+#define MSGPACK_ENDIAN_LITTLE_BYTE 0
 #define MSGPACK_ENDIAN_BIG_BYTE 1
 #endif
 
index 6086bd6187bb952849b69b28c60cc3dd091d4d25..399b18fb3450b6c72e2d78f43f0d9ecb2d532f60 100644 (file)
@@ -331,7 +331,9 @@ int msgpack_object_print_buffer(char *buffer, size_t buffer_size, msgpack_object
 
     case MSGPACK_OBJECT_STR:
         MSGPACK_CHECKED_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "\"");
-        MSGPACK_CHECKED_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "%.*s", (int)o.via.str.size, o.via.str.ptr);
+        if (o.via.str.size > 0) {
+            MSGPACK_CHECKED_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "%.*s", (int)o.via.str.size, o.via.str.ptr);
+        }
         MSGPACK_CHECKED_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "\"");
         break;
 
index ac112e1d920af94c172e8fab5d50e910df44b366..1ad8686bae3ce66d94f0dee3e21162f6764f3da7 100644 (file)
@@ -8,6 +8,8 @@
  *    http://www.boost.org/LICENSE_1_0.txt)
  */
 
+#include "vendor/msgpack/lttng-config.h"
+
 #if MSGPACK_ENDIAN_LITTLE_BYTE
 #define TAKE8_8(d)  ((uint8_t*)&d)[0]
 #define TAKE8_16(d) ((uint8_t*)&d)[0]
diff --git a/src/vendor/msgpack/predef.h b/src/vendor/msgpack/predef.h
deleted file mode 100644 (file)
index b2309ee..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
-Copyright Rene Rivera 2008-2015
-Distributed under the Boost Software License, Version 1.0.
-(See accompanying file LICENSE_1_0.txt or copy at
-http://www.boost.org/LICENSE_1_0.txt)
-*/
-
-#if !defined(MSGPACK_PREDEF_H) || defined(MSGPACK_PREDEF_INTERNAL_GENERATE_TESTS)
-#ifndef MSGPACK_PREDEF_H
-#define MSGPACK_PREDEF_H
-#endif
-
-#include <vendor/msgpack/predef/language.h>
-#include <vendor/msgpack/predef/architecture.h>
-#include <vendor/msgpack/predef/compiler.h>
-#include <vendor/msgpack/predef/library.h>
-#include <vendor/msgpack/predef/os.h>
-#include <vendor/msgpack/predef/other.h>
-#include <vendor/msgpack/predef/platform.h>
-#include <vendor/msgpack/predef/hardware.h>
-
-#include <vendor/msgpack/predef/version.h>
-
-#endif
index c494bae77a5e13225fb5f020e6eee0fd268397d9..572d8f27e683ed33704acae9a761db893e351810 100644 (file)
@@ -12,6 +12,7 @@
 
 #include <stdlib.h>
 #include <string.h>
+#include <assert.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -60,6 +61,9 @@ 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;
         size_t nsize = (sbuf->alloc) ?
@@ -83,6 +87,7 @@ static inline int msgpack_sbuffer_write(void* data, const char* buf, size_t len)
 
     memcpy(sbuf->data + sbuf->size, buf, len);
     sbuf->size += len;
+
     return 0;
 }
 
index ad5f615aa7e9e0fce4377c9a11300d07eb6df891..9cbb7a1db4d9e9f11bbbea852adbb122e8037c9f 100644 (file)
     typedef unsigned __int32 uint32_t;
     typedef signed __int64 int64_t;
     typedef unsigned __int64 uint64_t;
+#   if defined(_WIN64)
+        typedef signed __int64 intptr_t;
+        typedef unsigned __int64 uintptr_t;
+#   else
+        typedef signed __int32 intptr_t;
+        typedef unsigned __int32 uintptr_t;
+#   endif
 #elif defined(_MSC_VER)  // && _MSC_VER >= 1600
 #   include <stdint.h>
 #else
index 9db6023e7dd2996a891a90ed7a9a8f0cb9190793..763c732c7e2878ec49f9f85467c1a67c19e4a09e 100644 (file)
@@ -1,3 +1,3 @@
-#define MSGPACK_VERSION_MAJOR    3
-#define MSGPACK_VERSION_MINOR    3
+#define MSGPACK_VERSION_MAJOR    4
+#define MSGPACK_VERSION_MINOR    0
 #define MSGPACK_VERSION_REVISION 0
index 9c7b3b54976f955dd68d46f32f6f4cb24064c05c..a693bd1772c3582d2fb415c143e4bdbb579ae3ef 100644 (file)
@@ -22,7 +22,7 @@ bool msgpack_vrefbuffer_init(msgpack_vrefbuffer* vbuf,
         size_t ref_size, size_t chunk_size)
 {
     size_t nfirst;
-    struct iovec* array;
+    msgpack_iovec* array;
     msgpack_vrefbuffer_chunk* chunk;
 
     if (ref_size == 0) {
@@ -40,11 +40,11 @@ bool msgpack_vrefbuffer_init(msgpack_vrefbuffer* vbuf,
         return false;
     }
 
-    nfirst = (sizeof(struct iovec) < 72/2) ?
-            72 / sizeof(struct iovec) : 8;
+    nfirst = (sizeof(msgpack_iovec) < 72/2) ?
+            72 / sizeof(msgpack_iovec) : 8;
 
-    array = (struct iovec*)malloc(
-            sizeof(struct iovec) * nfirst);
+    array = (msgpack_iovec*)malloc(
+            sizeof(msgpack_iovec) * nfirst);
     if(array == NULL) {
         return false;
     }
@@ -114,8 +114,8 @@ int msgpack_vrefbuffer_append_ref(msgpack_vrefbuffer* vbuf,
         const size_t nused = (size_t)(vbuf->tail - vbuf->array);
         const size_t nnext = nused * 2;
 
-        struct iovec* nvec = (struct iovec*)realloc(
-                vbuf->array, sizeof(struct iovec)*nnext);
+        msgpack_iovec* nvec = (msgpack_iovec*)realloc(
+                vbuf->array, sizeof(msgpack_iovec)*nnext);
         if(nvec == NULL) {
             return -1;
         }
@@ -194,7 +194,7 @@ int msgpack_vrefbuffer_migrate(msgpack_vrefbuffer* vbuf, msgpack_vrefbuffer* to)
     {
         const size_t nused = (size_t)(vbuf->tail - vbuf->array);
         if(to->tail + nused < vbuf->end) {
-            struct iovec* nvec;
+            msgpack_iovec* nvec;
             const size_t tosize = (size_t)(to->tail - to->array);
             const size_t reqsize = nused + tosize;
             size_t nnext = (size_t)(to->end - to->array) * 2;
@@ -207,8 +207,8 @@ int msgpack_vrefbuffer_migrate(msgpack_vrefbuffer* vbuf, msgpack_vrefbuffer* to)
                 nnext = tmp_nnext;
             }
 
-            nvec = (struct iovec*)realloc(
-                    to->array, sizeof(struct iovec)*nnext);
+            nvec = (msgpack_iovec*)realloc(
+                    to->array, sizeof(msgpack_iovec)*nnext);
             if(nvec == NULL) {
                 free(empty);
                 return -1;
@@ -219,7 +219,7 @@ int msgpack_vrefbuffer_migrate(msgpack_vrefbuffer* vbuf, msgpack_vrefbuffer* to)
             to->tail  = nvec + tosize;
         }
 
-        memcpy(to->tail, vbuf->array, sizeof(struct iovec)*nused);
+        memcpy(to->tail, vbuf->array, sizeof(msgpack_iovec)*nused);
 
         to->tail += nused;
         vbuf->tail = vbuf->array;
index ab51aefa38140699edcf0b454d30cff40a23894a..c2633052bdbd9f863dba2a8c50efb06c3183376b 100644 (file)
 
 #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>
+typedef struct iovec msgpack_iovec;
 #else
-struct iovec {
+struct msgpack_iovec {
     void  *iov_base;
     size_t iov_len;
 };
+typedef struct msgpack_iovec msgpack_iovec;
 #endif
 
 #ifdef __cplusplus
@@ -43,9 +46,9 @@ typedef struct msgpack_vrefbuffer_inner_buffer {
 } msgpack_vrefbuffer_inner_buffer;
 
 typedef struct msgpack_vrefbuffer {
-    struct iovec* tail;
-    struct iovec* end;
-    struct iovec* array;
+    msgpack_iovec* tail;
+    msgpack_iovec* end;
+    msgpack_iovec* array;
 
     size_t chunk_size;
     size_t ref_size;
@@ -73,7 +76,7 @@ static inline void msgpack_vrefbuffer_free(msgpack_vrefbuffer* vbuf);
 
 static inline int msgpack_vrefbuffer_write(void* data, const char* buf, size_t len);
 
-static inline const struct iovec* msgpack_vrefbuffer_vec(const msgpack_vrefbuffer* vref);
+static inline const msgpack_iovec* msgpack_vrefbuffer_vec(const msgpack_vrefbuffer* vref);
 static inline size_t msgpack_vrefbuffer_veclen(const msgpack_vrefbuffer* vref);
 
 MSGPACK_DLLEXPORT
@@ -114,6 +117,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);
@@ -122,7 +128,7 @@ static inline int msgpack_vrefbuffer_write(void* data, const char* buf, size_t l
     }
 }
 
-static inline const struct iovec* msgpack_vrefbuffer_vec(const msgpack_vrefbuffer* vref)
+static inline const msgpack_iovec* msgpack_vrefbuffer_vec(const msgpack_vrefbuffer* vref)
 {
     return vref->array;
 }
index 524906fab145bffe3b52e02c51f9b42d58e96f6c..c38d627e7098682a100123d59d83a398ffe38e0b 100644 (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;
 
index 9005be7937399df8b9ccbf44904f3e3a8c5033e3..7facd547c288b0816630fa290dcc2139818ba8cc 100644 (file)
@@ -107,9 +107,9 @@ static inline void* msgpack_zone_malloc(msgpack_zone* zone, size_t size)
 {
     char* aligned =
         (char*)(
-            (size_t)(
+            (uintptr_t)(
                 zone->chunk_list.ptr + (MSGPACK_ZONE_ALIGN - 1)
-            ) / MSGPACK_ZONE_ALIGN * MSGPACK_ZONE_ALIGN
+            ) & ~(uintptr_t)(MSGPACK_ZONE_ALIGN - 1)
         );
     size_t adjusted_size = size + (size_t)(aligned - zone->chunk_list.ptr);
     if(zone->chunk_list.free >= adjusted_size) {
@@ -120,7 +120,7 @@ static inline void* msgpack_zone_malloc(msgpack_zone* zone, size_t size)
     {
         void* ptr = msgpack_zone_malloc_expand(zone, size + (MSGPACK_ZONE_ALIGN - 1));
         if (ptr) {
-            return (char*)((size_t)(ptr) / MSGPACK_ZONE_ALIGN * MSGPACK_ZONE_ALIGN);
+            return (char*)((uintptr_t)(ptr) & ~(uintptr_t)(MSGPACK_ZONE_ALIGN - 1));
         }
     }
     return NULL;
This page took 0.033032 seconds and 4 git commands to generate.