Bug 1545970 - make sure we only divide or modular TimeUnit on unsigned int32. r=jya

The way we use `operator/` on TimeUnit is usaually to divide 2 for the fuzz or to divide the playback rate, and the rate is always a unsigned int.

The `operator%` should also have same constraint, because there is meaningless to do such a operation on a negative value.

Differential Revision: https://phabricator.services.mozilla.com/D37310

--HG--
extra : moz-landing-system : lando
This commit is contained in:
alwu 2019-07-12 22:05:06 +00:00
Родитель a2577500f4
Коммит ac67bcfa81
1 изменённых файлов: 2 добавлений и 2 удалений

Просмотреть файл

@ -178,11 +178,11 @@ class TimeUnit final {
return TimeUnit::FromSeconds(ToSeconds() * aVal);
}
friend TimeUnit operator/(const TimeUnit& aUnit, int64_t aVal) {
MOZ_DIAGNOSTIC_ASSERT(INT32_MIN <= aVal && aVal <= INT32_MAX);
MOZ_DIAGNOSTIC_ASSERT(0 <= aVal && aVal <= UINT32_MAX);
return TimeUnit(aUnit.mValue / aVal);
}
friend TimeUnit operator%(const TimeUnit& aUnit, int64_t aVal) {
MOZ_DIAGNOSTIC_ASSERT(INT32_MIN <= aVal && aVal <= INT32_MAX);
MOZ_DIAGNOSTIC_ASSERT(0 <= aVal && aVal <= UINT32_MAX);
return TimeUnit(aUnit.mValue % aVal);
}