Fix sign conversion warning from clang:

googletest/samples/prime_tables.h:81:57: error:
implicit conversion changes signedness: 'int' to 'unsigned long'
[-Werror,-Wsign-conversion]
      : is_prime_size_(max + 1), is_prime_(new bool[max + 1]) {
                                           ~~~      ~~~~^~~

PiperOrigin-RevId: 506065360
Change-Id: Ida4550562531012c089e2f9fcf530b3a78889fa3
This commit is contained in:
Tom Hughes 2023-01-31 11:36:17 -08:00 committed by Copybara-Service
parent 4fb7039fda
commit d9251171f5

View File

@ -78,8 +78,9 @@ class PreCalculatedPrimeTable : public PrimeTable {
public:
// 'max' specifies the maximum number the prime table holds.
explicit PreCalculatedPrimeTable(int max)
: is_prime_size_(max + 1), is_prime_(new bool[max + 1]) {
CalculatePrimesUpTo(max);
: is_prime_size_(std::max(1, max + 1)),
is_prime_(new bool[static_cast<size_t>(is_prime_size_)]) {
CalculatePrimesUpTo(is_prime_size_ - 1);
}
~PreCalculatedPrimeTable() override { delete[] is_prime_; }