diff --git a/lib/ProfileData/InstrProfReader.cpp b/lib/ProfileData/InstrProfReader.cpp index 089dfca07f0..16a69cb5457 100644 --- a/lib/ProfileData/InstrProfReader.cpp +++ b/lib/ProfileData/InstrProfReader.cpp @@ -423,11 +423,11 @@ Error RawInstrProfReader::readRawCounts( // Check bounds. Note that the counter pointer embedded in the data record // may itself be corrupt. - if (NumCounters > MaxNumCounters) + if (MaxNumCounters < 0 || NumCounters > (uint32_t)MaxNumCounters) return error(instrprof_error::malformed); ptrdiff_t CounterOffset = getCounterOffset(CounterPtr); if (CounterOffset < 0 || CounterOffset > MaxNumCounters || - (CounterOffset + NumCounters) > MaxNumCounters) + ((uint32_t)CounterOffset + NumCounters) > (uint32_t)MaxNumCounters) return error(instrprof_error::malformed); auto RawCounts = makeArrayRef(getCounter(CounterOffset), NumCounters);