summaryrefslogtreecommitdiff
path: root/core/math
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2022-03-07 14:01:18 +0100
committerGitHub <noreply@github.com>2022-03-07 14:01:18 +0100
commit2a67b09b941647dc585685af9e9919d4f06d0ab2 (patch)
treed2a6d32661f7964a5458b665c884cb528904742d /core/math
parent6c3170e875bcb2606f08cde731f8b800801ef751 (diff)
parent0565676893aa761948e2a039c993e1d9d51f31f1 (diff)
Merge pull request #58858 from lawnjelly/safe_vectors4
Diffstat (limited to 'core/math')
-rw-r--r--core/math/vector2.h3
-rw-r--r--core/math/vector2i.h3
-rw-r--r--core/math/vector3.h2
-rw-r--r--core/math/vector3i.h3
4 files changed, 11 insertions, 0 deletions
diff --git a/core/math/vector2.h b/core/math/vector2.h
index a2680b84fc..bd67299f33 100644
--- a/core/math/vector2.h
+++ b/core/math/vector2.h
@@ -31,6 +31,7 @@
#ifndef VECTOR2_H
#define VECTOR2_H
+#include "core/error/error_macros.h"
#include "core/math/math_funcs.h"
class String;
@@ -60,9 +61,11 @@ struct _NO_DISCARD_ Vector2 {
};
_FORCE_INLINE_ real_t &operator[](int p_idx) {
+ DEV_ASSERT((unsigned int)p_idx < 2);
return coord[p_idx];
}
_FORCE_INLINE_ const real_t &operator[](int p_idx) const {
+ DEV_ASSERT((unsigned int)p_idx < 2);
return coord[p_idx];
}
diff --git a/core/math/vector2i.h b/core/math/vector2i.h
index 3f5f12d4dd..13b70031bd 100644
--- a/core/math/vector2i.h
+++ b/core/math/vector2i.h
@@ -31,6 +31,7 @@
#ifndef VECTOR2I_H
#define VECTOR2I_H
+#include "core/error/error_macros.h"
#include "core/math/math_funcs.h"
class String;
@@ -58,9 +59,11 @@ struct _NO_DISCARD_ Vector2i {
};
_FORCE_INLINE_ int32_t &operator[](int p_idx) {
+ DEV_ASSERT((unsigned int)p_idx < 2);
return coord[p_idx];
}
_FORCE_INLINE_ const int32_t &operator[](int p_idx) const {
+ DEV_ASSERT((unsigned int)p_idx < 2);
return coord[p_idx];
}
diff --git a/core/math/vector3.h b/core/math/vector3.h
index 89b0095741..b22ebeaf0a 100644
--- a/core/math/vector3.h
+++ b/core/math/vector3.h
@@ -59,10 +59,12 @@ struct _NO_DISCARD_ Vector3 {
};
_FORCE_INLINE_ const real_t &operator[](const int p_axis) const {
+ DEV_ASSERT((unsigned int)p_axis < 3);
return coord[p_axis];
}
_FORCE_INLINE_ real_t &operator[](const int p_axis) {
+ DEV_ASSERT((unsigned int)p_axis < 3);
return coord[p_axis];
}
diff --git a/core/math/vector3i.h b/core/math/vector3i.h
index 2a4c7e2e97..b49c1142ed 100644
--- a/core/math/vector3i.h
+++ b/core/math/vector3i.h
@@ -31,6 +31,7 @@
#ifndef VECTOR3I_H
#define VECTOR3I_H
+#include "core/error/error_macros.h"
#include "core/math/math_funcs.h"
class String;
@@ -54,10 +55,12 @@ struct _NO_DISCARD_ Vector3i {
};
_FORCE_INLINE_ const int32_t &operator[](const int p_axis) const {
+ DEV_ASSERT((unsigned int)p_axis < 3);
return coord[p_axis];
}
_FORCE_INLINE_ int32_t &operator[](const int p_axis) {
+ DEV_ASSERT((unsigned int)p_axis < 3);
return coord[p_axis];
}