Fix all -Wtype-limits warnings.

This commit is contained in:
marxin 2019-02-20 21:59:03 +01:00
parent a01dca79e2
commit 7de7f0ef17
9 changed files with 26 additions and 14 deletions

View File

@ -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.
*/

View File

@ -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

View File

@ -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();

View File

@ -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 {

View File

@ -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) {

View File

@ -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);

View File

@ -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);

View File

@ -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)))

View File

@ -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) {