[Scummvm-git-logs] scummvm master -> c2a12908c2c02790689ed87bfbfb543b33deddad
antoniou79
a.antoniou79 at gmail.com
Sat Jun 6 14:53:50 UTC 2020
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
c2a12908c2 COMMON: Use assert for CLIP() if bounds are not properly ordered (#2298)
Commit: c2a12908c2c02790689ed87bfbfb543b33deddad
https://github.com/scummvm/scummvm/commit/c2a12908c2c02790689ed87bfbfb543b33deddad
Author: Antoniou Athanasios (a.antoniou79 at gmail.com)
Date: 2020-06-06T17:53:47+03:00
Commit Message:
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
Changed paths:
common/util.h
diff --git a/common/util.h b/common/util.h
index 4a030d588c..f7c5cbd0ce 100644
--- a/common/util.h
+++ b/common/util.h
@@ -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.
More information about the Scummvm-git-logs
mailing list