summaryrefslogtreecommitdiff
path: root/upb
diff options
context:
space:
mode:
authorEsun Kim <veblush@google.com>2019-07-31 14:20:46 -0700
committerEsun Kim <veblush@google.com>2019-07-31 14:20:46 -0700
commitbc8b1a8f90706c7178fc0a128a7a791b85bbe88f (patch)
treec9732dec7f92679619dbb1589318b3f369f1f646 /upb
parent7e7cb5f831a97655a2d28ed49b485e14a9dd8188 (diff)
Fixed UBSAN issues
Diffstat (limited to 'upb')
-rw-r--r--upb/encode.c4
-rw-r--r--upb/msg.c2
-rw-r--r--upb/pb/compile_decoder.c2
-rw-r--r--upb/pb/varint.int.h8
4 files changed, 10 insertions, 6 deletions
diff --git a/upb/encode.c b/upb/encode.c
index 0f15803..7ec952e 100644
--- a/upb/encode.c
+++ b/upb/encode.c
@@ -25,8 +25,8 @@ static size_t upb_encode_varint(uint64_t val, char *buf) {
return i;
}
-static uint32_t upb_zzencode_32(int32_t n) { return (n << 1) ^ (n >> 31); }
-static uint64_t upb_zzencode_64(int64_t n) { return (n << 1) ^ (n >> 63); }
+static uint32_t upb_zzencode_32(int32_t n) { return ((uint32_t)n << 1) ^ (n >> 31); }
+static uint64_t upb_zzencode_64(int64_t n) { return ((uint64_t)n << 1) ^ (n >> 63); }
typedef struct {
upb_alloc *alloc;
diff --git a/upb/msg.c b/upb/msg.c
index 93d89a5..a77da56 100644
--- a/upb/msg.c
+++ b/upb/msg.c
@@ -5,7 +5,7 @@
#include "upb/port_def.inc"
-#define VOIDPTR_AT(msg, ofs) (void*)((char*)msg + ofs)
+#define VOIDPTR_AT(msg, ofs) (void*)((char*)msg + (int)ofs)
/* Internal members of a upb_msg. We can change this without breaking binary
* compatibility. We put these before the user's data. The user's upb_msg*
diff --git a/upb/pb/compile_decoder.c b/upb/pb/compile_decoder.c
index 1b40302..63d7fe2 100644
--- a/upb/pb/compile_decoder.c
+++ b/upb/pb/compile_decoder.c
@@ -149,7 +149,7 @@ static int32_t getofs(uint32_t instruction) {
static void setofs(uint32_t *instruction, int32_t ofs) {
if (op_has_longofs(*instruction)) {
- *instruction = getop(*instruction) | ofs << 8;
+ *instruction = getop(*instruction) | (uint32_t)ofs << 8;
} else {
*instruction = (*instruction & ~0xff00) | ((ofs & 0xff) << 8);
}
diff --git a/upb/pb/varint.int.h b/upb/pb/varint.int.h
index ddda694..ff1ca66 100644
--- a/upb/pb/varint.int.h
+++ b/upb/pb/varint.int.h
@@ -46,8 +46,12 @@ UPB_INLINE int32_t upb_zzdec_32(uint32_t n) {
UPB_INLINE int64_t upb_zzdec_64(uint64_t n) {
return (n >> 1) ^ -(int64_t)(n & 1);
}
-UPB_INLINE uint32_t upb_zzenc_32(int32_t n) { return (n << 1) ^ (n >> 31); }
-UPB_INLINE uint64_t upb_zzenc_64(int64_t n) { return (n << 1) ^ (n >> 63); }
+UPB_INLINE uint32_t upb_zzenc_32(int32_t n) {
+ return ((uint32_t)n << 1) ^ (n >> 31);
+}
+UPB_INLINE uint64_t upb_zzenc_64(int64_t n) {
+ return ((uint64_t)n << 1) ^ (n >> 63);
+}
/* Decoding *******************************************************************/
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback