Examples of errors detected by the V1083 diagnostic
V1083. Signed integer overflow in arithmetic expression. This leads to undefined behavior.
Godot Engine
V1083 Signed integer overflow is possible in 'p_width * p_height' arithmetic expression. This leads to undefined behavior. Left operand is in range '[0x1..0x1000000]', right operand is in range '[0x1..0x1000000]'. image.cpp 2200
class Image : public Resource
{
....
enum
{
MAX_WIDTH = (1 << 24), // force a limit somehow
MAX_HEIGHT = (1 << 24), // force a limit somehow
MAX_PIXELS = 268435456
};
....
}
void Image::initialize_data(int p_width, int p_height, bool p_use_mipmaps,
Format p_format, const Vector<uint8_t> &p_data)
{
....
ERR_FAIL_COND_MSG(p_width > MAX_WIDTH, "The Image width specified (" +
itos(p_width) +
" pixels) cannot be greater than " +
itos(MAX_WIDTH) +
" pixels.");
ERR_FAIL_COND_MSG(p_height > MAX_HEIGHT, "The Image height specified (" +
itos(p_height) +
" pixels) cannot be greater than " +
itos(MAX_HEIGHT) +
" pixels.");
ERR_FAIL_COND_MSG(p_width * p_height > MAX_PIXELS, // <=
"Too many pixels for image, maximum is " + itos(MAX_PIXELS));
....
}