summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorHein-Pieter van Braam <hp@tmm.cx>2019-01-30 02:12:41 +0100
committerHein-Pieter van Braam <hp@tmm.cx>2019-01-30 06:43:56 +0100
commitd308eb091a6c6d73442a118d7069e855ec2b1c6d (patch)
treef5c0a90604b707a9149446abc9dc3126b7621af5 /core
parent35bb52011a4cbcd8ca3779ab1761244f06a33127 (diff)
Fix many asan and ubsan reported issues
This allows most demos to run without any ubsan or asan errors. There are still some things in thirdpart/ and some things in AudioServer that needs a look but this fixes a lot of issues. This should help debug less obvious issues, hopefully. This fixes #25217 and fixes #25218
Diffstat (limited to 'core')
-rw-r--r--core/pair.h6
-rw-r--r--core/variant.cpp77
2 files changed, 53 insertions, 30 deletions
diff --git a/core/pair.h b/core/pair.h
index cb661160b5..9afaa726cb 100644
--- a/core/pair.h
+++ b/core/pair.h
@@ -37,7 +37,11 @@ struct Pair {
F first;
S second;
- Pair() {}
+ Pair() :
+ first(),
+ second() {
+ }
+
Pair(F p_first, const S &p_second) :
first(p_first),
second(p_second) {
diff --git a/core/variant.cpp b/core/variant.cpp
index 56b272cccf..2ee2e8e293 100644
--- a/core/variant.cpp
+++ b/core/variant.cpp
@@ -2816,27 +2816,37 @@ uint32_t Variant::hash() const {
const PoolVector<uint8_t> &arr = *reinterpret_cast<const PoolVector<uint8_t> *>(_data._mem);
int len = arr.size();
- PoolVector<uint8_t>::Read r = arr.read();
-
- return hash_djb2_buffer((uint8_t *)&r[0], len);
+ if (likely(len)) {
+ PoolVector<uint8_t>::Read r = arr.read();
+ return hash_djb2_buffer((uint8_t *)&r[0], len);
+ } else {
+ return hash_djb2_one_64(0);
+ }
} break;
case POOL_INT_ARRAY: {
const PoolVector<int> &arr = *reinterpret_cast<const PoolVector<int> *>(_data._mem);
int len = arr.size();
- PoolVector<int>::Read r = arr.read();
-
- return hash_djb2_buffer((uint8_t *)&r[0], len * sizeof(int));
+ if (likely(len)) {
+ PoolVector<int>::Read r = arr.read();
+ return hash_djb2_buffer((uint8_t *)&r[0], len * sizeof(int));
+ } else {
+ return hash_djb2_one_64(0);
+ }
} break;
case POOL_REAL_ARRAY: {
const PoolVector<real_t> &arr = *reinterpret_cast<const PoolVector<real_t> *>(_data._mem);
int len = arr.size();
- PoolVector<real_t>::Read r = arr.read();
- return hash_djb2_buffer((uint8_t *)&r[0], len * sizeof(real_t));
+ if (likely(len)) {
+ PoolVector<real_t>::Read r = arr.read();
+ return hash_djb2_buffer((uint8_t *)&r[0], len * sizeof(real_t));
+ } else {
+ return hash_djb2_one_float(0.0);
+ }
} break;
case POOL_STRING_ARRAY: {
@@ -2844,10 +2854,13 @@ uint32_t Variant::hash() const {
uint32_t hash = 5831;
const PoolVector<String> &arr = *reinterpret_cast<const PoolVector<String> *>(_data._mem);
int len = arr.size();
- PoolVector<String>::Read r = arr.read();
- for (int i = 0; i < len; i++) {
- hash = hash_djb2_one_32(r[i].hash(), hash);
+ if (likely(len)) {
+ PoolVector<String>::Read r = arr.read();
+
+ for (int i = 0; i < len; i++) {
+ hash = hash_djb2_one_32(r[i].hash(), hash);
+ }
}
return hash;
@@ -2857,48 +2870,54 @@ uint32_t Variant::hash() const {
uint32_t hash = 5831;
const PoolVector<Vector2> &arr = *reinterpret_cast<const PoolVector<Vector2> *>(_data._mem);
int len = arr.size();
- PoolVector<Vector2>::Read r = arr.read();
- for (int i = 0; i < len; i++) {
- hash = hash_djb2_one_float(r[i].x, hash);
- hash = hash_djb2_one_float(r[i].y, hash);
+ if (likely(len)) {
+ PoolVector<Vector2>::Read r = arr.read();
+
+ for (int i = 0; i < len; i++) {
+ hash = hash_djb2_one_float(r[i].x, hash);
+ hash = hash_djb2_one_float(r[i].y, hash);
+ }
}
return hash;
-
} break;
case POOL_VECTOR3_ARRAY: {
uint32_t hash = 5831;
const PoolVector<Vector3> &arr = *reinterpret_cast<const PoolVector<Vector3> *>(_data._mem);
int len = arr.size();
- PoolVector<Vector3>::Read r = arr.read();
- for (int i = 0; i < len; i++) {
- hash = hash_djb2_one_float(r[i].x, hash);
- hash = hash_djb2_one_float(r[i].y, hash);
- hash = hash_djb2_one_float(r[i].z, hash);
+ if (likely(len)) {
+ PoolVector<Vector3>::Read r = arr.read();
+
+ for (int i = 0; i < len; i++) {
+ hash = hash_djb2_one_float(r[i].x, hash);
+ hash = hash_djb2_one_float(r[i].y, hash);
+ hash = hash_djb2_one_float(r[i].z, hash);
+ }
}
return hash;
-
} break;
case POOL_COLOR_ARRAY: {
uint32_t hash = 5831;
const PoolVector<Color> &arr = *reinterpret_cast<const PoolVector<Color> *>(_data._mem);
int len = arr.size();
- PoolVector<Color>::Read r = arr.read();
- for (int i = 0; i < len; i++) {
- hash = hash_djb2_one_float(r[i].r, hash);
- hash = hash_djb2_one_float(r[i].g, hash);
- hash = hash_djb2_one_float(r[i].b, hash);
- hash = hash_djb2_one_float(r[i].a, hash);
+ if (likely(len)) {
+ PoolVector<Color>::Read r = arr.read();
+
+ for (int i = 0; i < len; i++) {
+ hash = hash_djb2_one_float(r[i].r, hash);
+ hash = hash_djb2_one_float(r[i].g, hash);
+ hash = hash_djb2_one_float(r[i].b, hash);
+ hash = hash_djb2_one_float(r[i].a, hash);
+ }
}
return hash;
-
} break;
default: {}
}