Bug 1587164 - Avoid left shift of negative value in TimestampWrapAroundHandler; r=bwc

The code for handling backwards wraps left shifts num_wrap_ - 1. If
num_wrap_ is zero, this results in a left shift of a negative value which
is undefined behaviour. This modifies the code to avoid the shift at the cost
of an extra multiplication.

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Dan Minor 2019-10-18 13:48:21 +00:00
Родитель a980b29c49
Коммит 188c0c2c70
1 изменённых файлов: 1 добавлений и 1 удалений

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

@ -139,7 +139,7 @@ int64_t TimestampWrapAroundHandler::Unwrap(uint32_t ts) {
++num_wrap_;
} else if ((ts - last_ts_) > 0xf0000000) {
// Backwards wrap. Unwrap with last wrap count and don't update last_ts_.
return ts + ((num_wrap_ - 1) << 32);
return ts + (num_wrap_ - 1)*((int64_t)1 << 32);
}
last_ts_ = ts;