Random integer generation was having a signed integer overflow
when calculating a range between min and max values.
When casting an overflowed value to unsigned int the result
by most (if not all) implementations would produce expected
results due to modulo wraparound. However, this is not guaranteed
to happen as signed integer overflow is regarded as undefined
behavior.
This change casts the min and max values to unsigned int which
has defined under- and overflow behavior.
VK-GL-CTS Issue: 3353
VK-GL-CTS Issue: 3355
VK-GL-CTS Issue: 3356
Affects: *
Components: Framework, Vulkan, OpenGL
Change-Id: I8dff7bf9517433e1699acfe1f6973ea8fb25e4f7
if (min == (int)0x80000000 && max == (int)0x7fffffff)
return (int)getUint32();
else
- return min + (int)(getUint32() % (deUint32)(max-min+1));
+ return min + (int)(getUint32() % ((deUint32)max - (deUint32)min + 1u));
}
// Template implementations