in resolution of [Wsign-compare] warning id 3

It is explicit that 'counter_value' is of unsigned type. It is implied that 'n' is a quantity/count. Given that 'n' is a signed int however, the apparent intended behavior of logging the first N state transistions is not ensured.

In resolution of the warning I cast 'n' to size_t. 
It is suggested however that the type n be changed from an int to an appropriate unsigned type in order to disqualify the possibility of the passed 'n' being negative; unintentional behavior.
This commit is contained in:
tg-at-google 2020-05-27 22:33:38 -04:00 committed by GitHub
parent 8dabb7fc05
commit 88b2336369
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -366,7 +366,7 @@ bool LogEveryNState::ShouldLog(int n) {
bool LogFirstNState::ShouldLog(int n) {
const uint32 counter_value = counter_.load(std::memory_order_relaxed);
if (counter_value < n) {
if (counter_value < (size_t)n) {
counter_.store(counter_value + 1, std::memory_order_relaxed);
return true;
}