Skip to content

Commit d925117

Browse files
thughescopybara-github
authored andcommitted
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
1 parent 4fb7039 commit d925117

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

googletest/samples/prime_tables.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,9 @@ class PreCalculatedPrimeTable : public PrimeTable {
7878
public:
7979
// 'max' specifies the maximum number the prime table holds.
8080
explicit PreCalculatedPrimeTable(int max)
81-
: is_prime_size_(max + 1), is_prime_(new bool[max + 1]) {
82-
CalculatePrimesUpTo(max);
81+
: is_prime_size_(std::max(1, max + 1)),
82+
is_prime_(new bool[static_cast<size_t>(is_prime_size_)]) {
83+
CalculatePrimesUpTo(is_prime_size_ - 1);
8384
}
8485
~PreCalculatedPrimeTable() override { delete[] is_prime_; }
8586

0 commit comments

Comments
 (0)