mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-31 07:53:36 +00:00
COMMON: Use assert for CLIP() if bounds are not properly ordered (#2298)
COMMON: Use assert in debug builds to prevent bad ordering of bounds The only macro to check against for debug vs release builds that I found is RELEASE_BUILD
This commit is contained in:
parent
b53a7db0da
commit
c2a12908c2
@ -49,7 +49,18 @@ template<typename T> inline T ABS(T x) { return (x >= 0) ? x : -x; }
|
||||
template<typename T> inline T MIN(T a, T b) { return (a < b) ? a : b; }
|
||||
template<typename T> inline T MAX(T a, T b) { return (a > b) ? a : b; }
|
||||
template<typename T> inline T CLIP(T v, T amin, T amax)
|
||||
{ if (v < amin) return amin; else if (v > amax) return amax; else return v; }
|
||||
{
|
||||
#if !defined(RELEASE_BUILD)
|
||||
// debug builds use this assert to pinpoint
|
||||
// any problematic cases, where amin and amax
|
||||
// are incorrectly ordered
|
||||
// and thus CLIP() would return an invalid result
|
||||
assert(amin <= amax);
|
||||
#endif
|
||||
if (v < amin) return amin;
|
||||
else if (v > amax) return amax;
|
||||
return v;
|
||||
}
|
||||
|
||||
/**
|
||||
* Template method which swaps the values of its two parameters.
|
||||
|
Loading…
x
Reference in New Issue
Block a user