forked from OSchip/llvm-project
[scudo] Fix implicitly narrow casting (NFC)
u16 may be promoted to int by arithmetic type conversion. Do an explicit cast to avoid certain compiler's warning. Differential Revision: https://reviews.llvm.org/D135945
This commit is contained in:
parent
d3366efd43
commit
fd7c7ad4fe
|
@ -31,7 +31,8 @@ template <class SizeClassAllocator> struct SizeClassAllocatorLocalCache {
|
||||||
void appendFromArray(CompactPtrT *Array, u16 N) {
|
void appendFromArray(CompactPtrT *Array, u16 N) {
|
||||||
DCHECK_LE(N, MaxNumCached - Count);
|
DCHECK_LE(N, MaxNumCached - Count);
|
||||||
memcpy(Batch + Count, Array, sizeof(Batch[0]) * N);
|
memcpy(Batch + Count, Array, sizeof(Batch[0]) * N);
|
||||||
Count += N;
|
// u16 will be promoted to int by arithmetic type conversion.
|
||||||
|
Count = static_cast<u16>(Count + N);
|
||||||
}
|
}
|
||||||
void clear() { Count = 0; }
|
void clear() { Count = 0; }
|
||||||
void add(CompactPtrT P) {
|
void add(CompactPtrT P) {
|
||||||
|
@ -189,7 +190,7 @@ private:
|
||||||
for (uptr I = 0; I < NumClasses; I++) {
|
for (uptr I = 0; I < NumClasses; I++) {
|
||||||
PerClass *P = &PerClassArray[I];
|
PerClass *P = &PerClassArray[I];
|
||||||
const uptr Size = SizeClassAllocator::getSizeByClassId(I);
|
const uptr Size = SizeClassAllocator::getSizeByClassId(I);
|
||||||
P->MaxCount = 2 * TransferBatch::getMaxCached(Size);
|
P->MaxCount = static_cast<u16>(2 * TransferBatch::getMaxCached(Size));
|
||||||
if (I != BatchClassId) {
|
if (I != BatchClassId) {
|
||||||
P->ClassSize = Size;
|
P->ClassSize = Size;
|
||||||
} else {
|
} else {
|
||||||
|
@ -221,7 +222,8 @@ private:
|
||||||
NOINLINE void drain(PerClass *C, uptr ClassId) {
|
NOINLINE void drain(PerClass *C, uptr ClassId) {
|
||||||
const u16 Count = Min(static_cast<u16>(C->MaxCount / 2), C->Count);
|
const u16 Count = Min(static_cast<u16>(C->MaxCount / 2), C->Count);
|
||||||
Allocator->pushBlocks(this, ClassId, &C->Chunks[0], Count);
|
Allocator->pushBlocks(this, ClassId, &C->Chunks[0], Count);
|
||||||
C->Count -= Count;
|
// u16 will be promoted to int by arithmetic type conversion.
|
||||||
|
C->Count = static_cast<u16>(C->Count - Count);
|
||||||
for (u16 I = 0; I < C->Count; I++)
|
for (u16 I = 0; I < C->Count; I++)
|
||||||
C->Chunks[I] = C->Chunks[I + Count];
|
C->Chunks[I] = C->Chunks[I + Count];
|
||||||
}
|
}
|
||||||
|
|
|
@ -436,7 +436,8 @@ private:
|
||||||
|
|
||||||
for (u32 I = 0; I < Size;) {
|
for (u32 I = 0; I < Size;) {
|
||||||
DCHECK_GE(BG->MaxCachedPerBatch, CurBatch->getCount());
|
DCHECK_GE(BG->MaxCachedPerBatch, CurBatch->getCount());
|
||||||
u16 UnusedSlots = BG->MaxCachedPerBatch - CurBatch->getCount();
|
u16 UnusedSlots =
|
||||||
|
static_cast<u16>(BG->MaxCachedPerBatch - CurBatch->getCount());
|
||||||
if (UnusedSlots == 0) {
|
if (UnusedSlots == 0) {
|
||||||
CurBatch = C->createBatch(ClassId, reinterpret_cast<void *>(
|
CurBatch = C->createBatch(ClassId, reinterpret_cast<void *>(
|
||||||
decompactPtr(ClassId, Array[I])));
|
decompactPtr(ClassId, Array[I])));
|
||||||
|
@ -444,6 +445,7 @@ private:
|
||||||
Batches.push_front(CurBatch);
|
Batches.push_front(CurBatch);
|
||||||
UnusedSlots = BG->MaxCachedPerBatch;
|
UnusedSlots = BG->MaxCachedPerBatch;
|
||||||
}
|
}
|
||||||
|
// `UnusedSlots` is u16 so the result will be also fit in u16.
|
||||||
u16 AppendSize = static_cast<u16>(Min<u32>(UnusedSlots, Size - I));
|
u16 AppendSize = static_cast<u16>(Min<u32>(UnusedSlots, Size - I));
|
||||||
CurBatch->appendFromArray(&Array[I], AppendSize);
|
CurBatch->appendFromArray(&Array[I], AppendSize);
|
||||||
I += AppendSize;
|
I += AppendSize;
|
||||||
|
|
|
@ -442,7 +442,8 @@ private:
|
||||||
|
|
||||||
for (u32 I = 0; I < Size;) {
|
for (u32 I = 0; I < Size;) {
|
||||||
DCHECK_GE(BG->MaxCachedPerBatch, CurBatch->getCount());
|
DCHECK_GE(BG->MaxCachedPerBatch, CurBatch->getCount());
|
||||||
u16 UnusedSlots = BG->MaxCachedPerBatch - CurBatch->getCount();
|
u16 UnusedSlots =
|
||||||
|
static_cast<u16>(BG->MaxCachedPerBatch - CurBatch->getCount());
|
||||||
if (UnusedSlots == 0) {
|
if (UnusedSlots == 0) {
|
||||||
CurBatch = C->createBatch(ClassId, reinterpret_cast<void *>(
|
CurBatch = C->createBatch(ClassId, reinterpret_cast<void *>(
|
||||||
decompactPtr(ClassId, Array[I])));
|
decompactPtr(ClassId, Array[I])));
|
||||||
|
|
Loading…
Reference in New Issue