summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorLajos Molnar <lajos@google.com>2015-05-13 17:07:51 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2015-05-13 17:07:51 +0000
commit814463259cfc0b3c30535e6cba89a736f56c4a16 (patch)
tree4d3c7e3a9b3f102c6e55a4d685271d578cdd2a64 /include
parentdce0777a1c82557fc108dfcd9665e06d583780d1 (diff)
parent0eb7c79398ef04e457c76f117feef6d7bcbbc684 (diff)
downloadframeworks_av-814463259cfc0b3c30535e6cba89a736f56c4a16.zip
frameworks_av-814463259cfc0b3c30535e6cba89a736f56c4a16.tar.gz
frameworks_av-814463259cfc0b3c30535e6cba89a736f56c4a16.tar.bz2
am 0eb7c793: am b5fbb811: am c8c86c1d: am bcf2becf: am c531d995: am 438217a0: Merge "Add AUtils::isInRange, and use it to detect malformed MPEG4 nal sizes" into lmp-dev
* commit '0eb7c79398ef04e457c76f117feef6d7bcbbc684': Add AUtils::isInRange, and use it to detect malformed MPEG4 nal sizes
Diffstat (limited to 'include')
-rw-r--r--include/media/stagefright/foundation/AUtils.h22
1 files changed, 22 insertions, 0 deletions
diff --git a/include/media/stagefright/foundation/AUtils.h b/include/media/stagefright/foundation/AUtils.h
index d7ecf50..47444c1 100644
--- a/include/media/stagefright/foundation/AUtils.h
+++ b/include/media/stagefright/foundation/AUtils.h
@@ -61,6 +61,28 @@ inline static const T &max(const T &a, const T &b) {
return a > b ? a : b;
}
+template<class T>
+void ENSURE_UNSIGNED_TYPE() {
+ T TYPE_MUST_BE_UNSIGNED[(T)-1 < 0 ? -1 : 0] __unused;
+}
+
+// needle is in range [hayStart, hayStart + haySize)
+template<class T, class U>
+inline static bool isInRange(const T &hayStart, const U &haySize, const T &needle) {
+ ENSURE_UNSIGNED_TYPE<U>();
+ return (T)(hayStart + haySize) >= hayStart && needle >= hayStart && (U)(needle - hayStart) < haySize;
+}
+
+// [needleStart, needleStart + needleSize) is in range [hayStart, hayStart + haySize)
+template<class T, class U>
+inline static bool isInRange(
+ const T &hayStart, const U &haySize, const T &needleStart, const U &needleSize) {
+ ENSURE_UNSIGNED_TYPE<U>();
+ return isInRange(hayStart, haySize, needleStart)
+ && (T)(needleStart + needleSize) >= needleStart
+ && (U)(needleStart + needleSize - hayStart) <= haySize;
+}
+
/* T must be integer type, period must be positive */
template<class T>
inline static T periodicError(const T &val, const T &period) {