summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/error_macros.h14
-rw-r--r--core/typedefs.h2
-rw-r--r--modules/enet/networked_multiplayer_enet.cpp1
-rw-r--r--modules/gdscript/gdscript_tokenizer.cpp4
-rw-r--r--platform/x11/joypad_linux.cpp2
-rw-r--r--platform/x11/os_x11.cpp2
-rw-r--r--scene/3d/voxel_light_baker.cpp2
-rw-r--r--servers/audio/reverb_sw.cpp3
-rw-r--r--servers/visual/visual_server_scene.cpp10
9 files changed, 26 insertions, 14 deletions
diff --git a/core/error_macros.h b/core/error_macros.h
index 60a0e8a7dc..3aa8ed4596 100644
--- a/core/error_macros.h
+++ b/core/error_macros.h
@@ -154,6 +154,20 @@ extern bool _err_error_exists;
_err_error_exists = false; \
} while (0); // (*)
+/** An index has failed if m_index >=m_size, the function exists.
+* This function returns an error value, if returning Error, please select the most
+* appropriate error condition from error_macros.h
+*/
+
+#define ERR_FAIL_UNSIGNED_INDEX_V(m_index, m_size, m_retval) \
+ do { \
+ if (unlikely((m_index) >= (m_size))) { \
+ _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size)); \
+ return m_retval; \
+ } else \
+ _err_error_exists = false; \
+ } while (0); // (*)
+
/** Use this one if there is no sensible fallback, that is, the error is unrecoverable.
* We'll return a null reference and try to keep running.
*/
diff --git a/core/typedefs.h b/core/typedefs.h
index 0005e5e6ee..e01e1c00b9 100644
--- a/core/typedefs.h
+++ b/core/typedefs.h
@@ -116,6 +116,8 @@ T *_nullptr() {
#define ABS(m_v) (((m_v) < 0) ? (-(m_v)) : (m_v))
#endif
+#define ABSDIFF(x, y) (((x) < (y)) ? ((y) - (x)) : ((x) - (y)))
+
#ifndef SGN
#define SGN(m_v) (((m_v) < 0) ? (-1.0) : (+1.0))
#endif
diff --git a/modules/enet/networked_multiplayer_enet.cpp b/modules/enet/networked_multiplayer_enet.cpp
index 871c33bb35..000917507a 100644
--- a/modules/enet/networked_multiplayer_enet.cpp
+++ b/modules/enet/networked_multiplayer_enet.cpp
@@ -433,7 +433,6 @@ bool NetworkedMultiplayerENet::is_server() const {
void NetworkedMultiplayerENet::close_connection(uint32_t wait_usec) {
ERR_FAIL_COND(!active);
- ERR_FAIL_COND(wait_usec < 0);
_pop_current_packet();
diff --git a/modules/gdscript/gdscript_tokenizer.cpp b/modules/gdscript/gdscript_tokenizer.cpp
index dc9f2db331..480bf0fa3c 100644
--- a/modules/gdscript/gdscript_tokenizer.cpp
+++ b/modules/gdscript/gdscript_tokenizer.cpp
@@ -1417,7 +1417,7 @@ StringName GDScriptTokenizerBuffer::get_token_identifier(int p_offset) const {
ERR_FAIL_INDEX_V(offset, tokens.size(), StringName());
uint32_t identifier = tokens[offset] >> TOKEN_BITS;
- ERR_FAIL_INDEX_V(identifier, (uint32_t)identifiers.size(), StringName());
+ ERR_FAIL_UNSIGNED_INDEX_V(identifier, identifiers.size(), StringName());
return identifiers[identifier];
}
@@ -1473,7 +1473,7 @@ const Variant &GDScriptTokenizerBuffer::get_token_constant(int p_offset) const {
int offset = token + p_offset;
ERR_FAIL_INDEX_V(offset, tokens.size(), nil);
uint32_t constant = tokens[offset] >> TOKEN_BITS;
- ERR_FAIL_INDEX_V(constant, (uint32_t)constants.size(), nil);
+ ERR_FAIL_UNSIGNED_INDEX_V(constant, constants.size(), nil);
return constants[constant];
}
String GDScriptTokenizerBuffer::get_token_error(int p_offset) const {
diff --git a/platform/x11/joypad_linux.cpp b/platform/x11/joypad_linux.cpp
index 907c652ab4..7cf0a1ef1e 100644
--- a/platform/x11/joypad_linux.cpp
+++ b/platform/x11/joypad_linux.cpp
@@ -476,7 +476,7 @@ void JoypadLinux::process_joypads() {
// ev may be tainted and out of MAX_KEY range, which will cause
// joy->key_map[ev.code] to crash
- if (ev.code < 0 || ev.code >= MAX_KEY)
+ if (ev.code >= MAX_KEY)
return;
switch (ev.type) {
diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp
index 8db4635d68..879642d8f9 100644
--- a/platform/x11/os_x11.cpp
+++ b/platform/x11/os_x11.cpp
@@ -1743,7 +1743,7 @@ void OS_X11::handle_key_event(XKeyEvent *p_event, bool p_echo) {
// is correct, but the xorg developers are
// not very helpful today.
- ::Time tresh = ABS(peek_event.xkey.time - xkeyevent->time);
+ ::Time tresh = ABSDIFF(peek_event.xkey.time, xkeyevent->time);
if (peek_event.type == KeyPress && tresh < 5) {
KeySym rk;
XLookupString((XKeyEvent *)&peek_event, str, 256, &rk, NULL);
diff --git a/scene/3d/voxel_light_baker.cpp b/scene/3d/voxel_light_baker.cpp
index 91b3ea6ca0..42c2318701 100644
--- a/scene/3d/voxel_light_baker.cpp
+++ b/scene/3d/voxel_light_baker.cpp
@@ -2208,7 +2208,7 @@ PoolVector<int> VoxelLightBaker::create_gi_probe_data() {
}
{
- uint16_t alpha = CLAMP(uint32_t(bake_cells[i].alpha * 65535.0), 0, 65535);
+ uint16_t alpha = MAX(uint32_t(bake_cells[i].alpha * 65535.0), 65535);
uint16_t level = bake_cells[i].level;
w32[ofs++] = (uint32_t(level) << 16) | uint32_t(alpha);
diff --git a/servers/audio/reverb_sw.cpp b/servers/audio/reverb_sw.cpp
index 8adc21b406..63bf1a7eaa 100644
--- a/servers/audio/reverb_sw.cpp
+++ b/servers/audio/reverb_sw.cpp
@@ -39,9 +39,6 @@
#define rangeloop(c, min, max) \
for ((c) = (min); (c) < (max); (c)++)
-#define ABSDIFF(x, y) \
- (((x) < (y)) ? ((y) - (x)) : ((x) - (y)))
-
#define MULSHIFT_S32(Factor1, Factor2, Bits) \
((int)(((int64_t)(Factor1) * (Factor2)) >> (Bits)))
diff --git a/servers/visual/visual_server_scene.cpp b/servers/visual/visual_server_scene.cpp
index b561351374..01d00ccc21 100644
--- a/servers/visual/visual_server_scene.cpp
+++ b/servers/visual/visual_server_scene.cpp
@@ -2480,7 +2480,7 @@ void VisualServerScene::_setup_gi_probe(Instance *p_instance) {
uint32_t a = uint32_t(alpha_block[x][y]) - min_alpha;
//convert range to 3 bits
a = int((a * 7.0 / (max_alpha - min_alpha)) + 0.5);
- a = CLAMP(a, 0, 7); //just to be sure
+ a = MAX(a, 7); //just to be sure
a = 7 - a; //because range is inverted in this mode
if (a == 0) {
//do none, remain
@@ -2924,10 +2924,10 @@ void VisualServerScene::_bake_gi_probe(Instance *p_gi_probe) {
uint32_t mm_ofs = sizes[0] * sizes[1] * (local_data[idx].pos[2]) + sizes[0] * (local_data[idx].pos[1]) + (local_data[idx].pos[0]);
mm_ofs *= 4; //for RGBA (4 bytes)
- mipmapw[mm_ofs + 0] = uint8_t(CLAMP(r2, 0, 255));
- mipmapw[mm_ofs + 1] = uint8_t(CLAMP(g, 0, 255));
- mipmapw[mm_ofs + 2] = uint8_t(CLAMP(b, 0, 255));
- mipmapw[mm_ofs + 3] = uint8_t(CLAMP(a, 0, 255));
+ mipmapw[mm_ofs + 0] = uint8_t(MAX(r2, 255));
+ mipmapw[mm_ofs + 1] = uint8_t(MAX(g, 255));
+ mipmapw[mm_ofs + 2] = uint8_t(MAX(b, 255));
+ mipmapw[mm_ofs + 3] = uint8_t(MAX(a, 255));
}
}
} else if (probe_data->dynamic.compression == RasterizerStorage::GI_PROBE_S3TC) {