From 965ad74482e01c21c48bd946b22800c12d7cd706 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Wed, 2 Sep 2020 09:06:29 -0600 Subject: [PATCH] Update to protobuf-c 1.3.3 --- include/log_server.pb-c.h | 2 +- include/protobuf-c/protobuf-c.h | 4 ++-- lib/logsrv/protobuf-c.c | 26 ++++++++++---------------- 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/include/log_server.pb-c.h b/include/log_server.pb-c.h index f68a3375b..e3b1fbb51 100644 --- a/include/log_server.pb-c.h +++ b/include/log_server.pb-c.h @@ -10,7 +10,7 @@ PROTOBUF_C__BEGIN_DECLS #if PROTOBUF_C_VERSION_NUMBER < 1003000 # error This file was generated by a newer version of protoc-c which is incompatible with your libprotobuf-c headers. Please update your headers. -#elif 1003002 < PROTOBUF_C_MIN_COMPILER_VERSION +#elif 1003003 < PROTOBUF_C_MIN_COMPILER_VERSION # error This file was generated by an older version of protoc-c which is incompatible with your libprotobuf-c headers. Please regenerate this file with a newer version of protoc-c. #endif diff --git a/include/protobuf-c/protobuf-c.h b/include/protobuf-c/protobuf-c.h index ef579b7e0..8348cf199 100644 --- a/include/protobuf-c/protobuf-c.h +++ b/include/protobuf-c/protobuf-c.h @@ -790,13 +790,13 @@ protobuf_c_version_number(void); * The version of the protobuf-c headers, represented as a string using the same * format as protobuf_c_version(). */ -#define PROTOBUF_C_VERSION "1.3.2" +#define PROTOBUF_C_VERSION "1.3.3" /** * The version of the protobuf-c headers, represented as an integer using the * same format as protobuf_c_version_number(). */ -#define PROTOBUF_C_VERSION_NUMBER 1003002 +#define PROTOBUF_C_VERSION_NUMBER 1003003 /** * The minimum protoc-c version which works with the current version of the diff --git a/lib/logsrv/protobuf-c.c b/lib/logsrv/protobuf-c.c index 7a6b56d32..23fe295db 100644 --- a/lib/logsrv/protobuf-c.c +++ b/lib/logsrv/protobuf-c.c @@ -312,10 +312,9 @@ int32_size(int32_t v) static inline uint32_t zigzag32(int32_t v) { - if (v < 0) - return (-(uint32_t)v) * 2 - 1; - else - return (uint32_t)(v) * 2; + // Note: the right-shift must be arithmetic + // Note: left shift must be unsigned because of overflow + return ((uint32_t)(v) << 1) ^ (uint32_t)(v >> 31); } /** @@ -377,10 +376,9 @@ uint64_size(uint64_t v) static inline uint64_t zigzag64(int64_t v) { - if (v < 0) - return (-(uint64_t)v) * 2 - 1; - else - return (uint64_t)(v) * 2; + // Note: the right-shift must be arithmetic + // Note: left shift must be unsigned because of overflow + return ((uint64_t)(v) << 1) ^ (uint64_t)(v >> 63); } /** @@ -2423,10 +2421,8 @@ parse_int32(unsigned len, const uint8_t *data) static inline int32_t unzigzag32(uint32_t v) { - if (v & 1) - return -(v >> 1) - 1; - else - return v >> 1; + // Note: Using unsigned types prevents undefined behavior + return (int32_t)((v >> 1) ^ (~(v & 1) + 1)); } static inline uint32_t @@ -2467,10 +2463,8 @@ parse_uint64(unsigned len, const uint8_t *data) static inline int64_t unzigzag64(uint64_t v) { - if (v & 1) - return -(v >> 1) - 1; - else - return v >> 1; + // Note: Using unsigned types prevents undefined behavior + return (int64_t)((v >> 1) ^ (~(v & 1) + 1)); } static inline uint64_t