Wsign-conversion for public headers
This is an Android request for our public headers, much like warning about unused parameters. See bug. In general I've made two kinds of source changes: 1) more commonly, explicitly cast to the type which is being implicitly cast to at head; 2) less commonly, flip signedness of a value we're storing to match how it's used more smoothly. Much of this is self inflicted inconsistent use of size_t, unsigned, int, int32_t, uint32_t, etc. SkTArray is particularly tricky because of its std::vector half-compatibility. E.g. resize() takes size_t, but operator[] takes int. ¯\_(ツ)_/¯ Bug: skia:9847 Change-Id: I64626a529e1662b3d3020bc03d477fc641eda544 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/293436 Reviewed-by: Mike Reed <reed@google.com> Commit-Queue: Mike Klein <mtklein@google.com>
This commit is contained in:
parent
e8121e57ab
commit
89c909efee
@ -430,6 +430,10 @@ config("warnings") {
|
||||
"-Wno-weak-vtables",
|
||||
]
|
||||
|
||||
# Turn back on after -Wno-conversion.
|
||||
# This only affects public headers... see :warnings_except_public_headers.
|
||||
cflags += [ "-Wsign-conversion" ]
|
||||
|
||||
# We are unlikely to want to fix these.
|
||||
cflags += [
|
||||
"-Wno-covered-switch-default",
|
||||
@ -483,7 +487,10 @@ config("warnings") {
|
||||
}
|
||||
config("warnings_except_public_headers") {
|
||||
if (!is_win || is_clang) {
|
||||
cflags = [ "-Wno-unused-parameter" ]
|
||||
cflags = [
|
||||
"-Wno-sign-conversion",
|
||||
"-Wno-unused-parameter",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -74,7 +74,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
uint32_t fValue;
|
||||
int32_t fValue;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -581,20 +581,22 @@ public:
|
||||
|
||||
@return width() times bytesPerPixel() as unsigned 64-bit integer
|
||||
*/
|
||||
uint64_t minRowBytes64() const { return sk_64_mul(this->width(), this->bytesPerPixel()); }
|
||||
uint64_t minRowBytes64() const {
|
||||
return (uint64_t)sk_64_mul(this->width(), this->bytesPerPixel());
|
||||
}
|
||||
|
||||
/** Returns minimum bytes per row, computed from pixel width() and SkColorType, which
|
||||
specifies bytesPerPixel(). SkBitmap maximum value for row bytes must fit
|
||||
in 31 bits.
|
||||
|
||||
@return width() times bytesPerPixel() as signed 32-bit integer
|
||||
@return width() times bytesPerPixel() as size_t
|
||||
*/
|
||||
size_t minRowBytes() const {
|
||||
uint64_t minRowBytes = this->minRowBytes64();
|
||||
if (!SkTFitsIn<int32_t>(minRowBytes)) {
|
||||
return 0;
|
||||
}
|
||||
return SkTo<int32_t>(minRowBytes);
|
||||
return (size_t)minRowBytes;
|
||||
}
|
||||
|
||||
/** Returns byte offset of pixel from pixel base address.
|
||||
|
@ -1717,7 +1717,7 @@ public:
|
||||
fMat[kMPersp1] = 0;
|
||||
fMat[kMPersp2] = 1;
|
||||
|
||||
unsigned mask = 0;
|
||||
int mask = 0;
|
||||
if (sx != 1 || sy != 1) {
|
||||
mask |= kScale_Mask;
|
||||
}
|
||||
@ -1761,12 +1761,12 @@ private:
|
||||
kPerspective_Mask |
|
||||
kRectStaysRect_Mask;
|
||||
|
||||
SkScalar fMat[9];
|
||||
mutable uint32_t fTypeMask;
|
||||
SkScalar fMat[9];
|
||||
mutable int32_t fTypeMask;
|
||||
|
||||
constexpr SkMatrix(SkScalar sx, SkScalar kx, SkScalar tx,
|
||||
SkScalar ky, SkScalar sy, SkScalar ty,
|
||||
SkScalar p0, SkScalar p1, SkScalar p2, uint32_t typeMask)
|
||||
SkScalar p0, SkScalar p1, SkScalar p2, int typeMask)
|
||||
: fMat{sx, kx, tx,
|
||||
ky, sy, ty,
|
||||
p0, p1, p2}
|
||||
@ -1782,18 +1782,18 @@ private:
|
||||
SkASSERT(kUnknown_Mask == mask || (mask & kAllMasks) == mask ||
|
||||
((kUnknown_Mask | kOnlyPerspectiveValid_Mask) & mask)
|
||||
== (kUnknown_Mask | kOnlyPerspectiveValid_Mask));
|
||||
fTypeMask = SkToU8(mask);
|
||||
fTypeMask = mask;
|
||||
}
|
||||
|
||||
void orTypeMask(int mask) {
|
||||
SkASSERT((mask & kORableMasks) == mask);
|
||||
fTypeMask = SkToU8(fTypeMask | mask);
|
||||
fTypeMask |= mask;
|
||||
}
|
||||
|
||||
void clearTypeMask(int mask) {
|
||||
// only allow a valid mask
|
||||
SkASSERT((mask & kAllMasks) == mask);
|
||||
fTypeMask = fTypeMask & ~mask;
|
||||
fTypeMask &= ~mask;
|
||||
}
|
||||
|
||||
TypeMask getPerspectiveTypeMaskOnly() const {
|
||||
|
@ -369,7 +369,7 @@ public:
|
||||
const uint8_t* addr8(int x, int y) const {
|
||||
SkASSERT((unsigned)x < (unsigned)fInfo.width());
|
||||
SkASSERT((unsigned)y < (unsigned)fInfo.height());
|
||||
return (const uint8_t*)((const char*)this->addr8() + y * fRowBytes + (x << 0));
|
||||
return (const uint8_t*)((const char*)this->addr8() + (size_t)y * fRowBytes + (x << 0));
|
||||
}
|
||||
|
||||
/** Returns readable pixel address at (x, y).
|
||||
@ -387,7 +387,7 @@ public:
|
||||
const uint16_t* addr16(int x, int y) const {
|
||||
SkASSERT((unsigned)x < (unsigned)fInfo.width());
|
||||
SkASSERT((unsigned)y < (unsigned)fInfo.height());
|
||||
return (const uint16_t*)((const char*)this->addr16() + y * fRowBytes + (x << 1));
|
||||
return (const uint16_t*)((const char*)this->addr16() + (size_t)y * fRowBytes + (x << 1));
|
||||
}
|
||||
|
||||
/** Returns readable pixel address at (x, y).
|
||||
@ -405,7 +405,7 @@ public:
|
||||
const uint32_t* addr32(int x, int y) const {
|
||||
SkASSERT((unsigned)x < (unsigned)fInfo.width());
|
||||
SkASSERT((unsigned)y < (unsigned)fInfo.height());
|
||||
return (const uint32_t*)((const char*)this->addr32() + y * fRowBytes + (x << 2));
|
||||
return (const uint32_t*)((const char*)this->addr32() + (size_t)y * fRowBytes + (x << 2));
|
||||
}
|
||||
|
||||
/** Returns readable pixel address at (x, y).
|
||||
@ -423,7 +423,7 @@ public:
|
||||
const uint64_t* addr64(int x, int y) const {
|
||||
SkASSERT((unsigned)x < (unsigned)fInfo.width());
|
||||
SkASSERT((unsigned)y < (unsigned)fInfo.height());
|
||||
return (const uint64_t*)((const char*)this->addr64() + y * fRowBytes + (x << 3));
|
||||
return (const uint64_t*)((const char*)this->addr64() + (size_t)y * fRowBytes + (x << 3));
|
||||
}
|
||||
|
||||
/** Returns readable pixel address at (x, y).
|
||||
|
@ -542,7 +542,7 @@ template <typename T> static constexpr bool SkIsAlignPtr(T x) {
|
||||
|
||||
typedef uint32_t SkFourByteTag;
|
||||
static inline constexpr SkFourByteTag SkSetFourByteTag(char a, char b, char c, char d) {
|
||||
return (((uint8_t)a << 24) | ((uint8_t)b << 16) | ((uint8_t)c << 8) | (uint8_t)d);
|
||||
return (((uint32_t)a << 24) | ((uint32_t)b << 16) | ((uint32_t)c << 8) | (uint32_t)d);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -105,7 +105,7 @@ struct GrVkYcbcrConversionInfo {
|
||||
VkChromaLocation yChromaOffset,
|
||||
VkFilter chromaFilter,
|
||||
VkBool32 forceExplicitReconstruction,
|
||||
uint64_t externalFormat,
|
||||
int64_t externalFormat,
|
||||
VkFormatFeatureFlags externalFormatFeatures)
|
||||
: GrVkYcbcrConversionInfo(VK_FORMAT_UNDEFINED, externalFormat, ycbcrModel, ycbcrRange,
|
||||
xChromaOffset, yChromaOffset, chromaFilter,
|
||||
@ -135,7 +135,7 @@ struct GrVkYcbcrConversionInfo {
|
||||
|
||||
// The external format. Must be non-zero for external images, zero otherwise.
|
||||
// Should be compatible to be used in a VkExternalFormatANDROID struct.
|
||||
uint64_t fExternalFormat;
|
||||
int64_t fExternalFormat;
|
||||
|
||||
VkSamplerYcbcrModelConversion fYcbcrModel;
|
||||
VkSamplerYcbcrRange fYcbcrRange;
|
||||
|
@ -62,7 +62,7 @@ protected:
|
||||
} else {
|
||||
size_t bytes = that.size();
|
||||
SkASSERT(SkIsAlign4(bytes));
|
||||
fKey.reset(SkToInt(bytes / sizeof(uint32_t)));
|
||||
fKey.reset(bytes / sizeof(uint32_t));
|
||||
memcpy(fKey.get(), that.fKey.get(), bytes);
|
||||
this->validate();
|
||||
}
|
||||
@ -103,10 +103,10 @@ protected:
|
||||
class Builder {
|
||||
public:
|
||||
Builder(GrResourceKey* key, uint32_t domain, int data32Count) : fKey(key) {
|
||||
SkASSERT(data32Count >= 0);
|
||||
size_t count = SkToSizeT(data32Count);
|
||||
SkASSERT(domain != kInvalidDomain);
|
||||
key->fKey.reset(kMetaDataCnt + data32Count);
|
||||
int size = (data32Count + kMetaDataCnt) * sizeof(uint32_t);
|
||||
key->fKey.reset(kMetaDataCnt + count);
|
||||
size_t size = (count + kMetaDataCnt) * sizeof(uint32_t);
|
||||
SkASSERT(SkToU16(size) == size);
|
||||
SkASSERT(SkToU16(domain) == domain);
|
||||
key->fKey[kDomainAndSize_MetaDataIdx] = domain | (size << 16);
|
||||
@ -128,7 +128,7 @@ protected:
|
||||
SkASSERT(fKey);
|
||||
SkDEBUGCODE(size_t dataCount = fKey->internalSize() / sizeof(uint32_t) - kMetaDataCnt;)
|
||||
SkASSERT(SkToU32(dataIdx) < dataCount);
|
||||
return fKey->fKey[kMetaDataCnt + dataIdx];
|
||||
return fKey->fKey[(int)kMetaDataCnt + dataIdx];
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -62,7 +62,7 @@ typedef int32_t SkFixed;
|
||||
SkASSERT(n >= -32768 && n <= 32767);
|
||||
// Left shifting a negative value has undefined behavior in C, so we cast to unsigned before
|
||||
// shifting.
|
||||
return (unsigned)n << 16;
|
||||
return (SkFixed)( (unsigned)n << 16 );
|
||||
}
|
||||
#else
|
||||
// Left shifting a negative value has undefined behavior in C, so we cast to unsigned before
|
||||
@ -76,13 +76,13 @@ typedef int32_t SkFixed;
|
||||
#define SkFixedFloorToInt(x) ((x) >> 16)
|
||||
|
||||
static inline SkFixed SkFixedRoundToFixed(SkFixed x) {
|
||||
return (x + SK_FixedHalf) & 0xFFFF0000;
|
||||
return (SkFixed)( (uint32_t)(x + SK_FixedHalf) & 0xFFFF0000 );
|
||||
}
|
||||
static inline SkFixed SkFixedCeilToFixed(SkFixed x) {
|
||||
return (x + SK_Fixed1 - 1) & 0xFFFF0000;
|
||||
return (SkFixed)( (uint32_t)(x + SK_Fixed1 - 1) & 0xFFFF0000 );
|
||||
}
|
||||
static inline SkFixed SkFixedFloorToFixed(SkFixed x) {
|
||||
return x & 0xFFFF0000;
|
||||
return (SkFixed)( (uint32_t)x & 0xFFFF0000 );
|
||||
}
|
||||
|
||||
#define SkFixedAbs(x) SkAbs32(x)
|
||||
|
@ -74,7 +74,7 @@ static int SkColorTypeShiftPerPixel(SkColorType ct) {
|
||||
}
|
||||
|
||||
static inline size_t SkColorTypeMinRowBytes(SkColorType ct, int width) {
|
||||
return width * SkColorTypeBytesPerPixel(ct);
|
||||
return (size_t)(width * SkColorTypeBytesPerPixel(ct));
|
||||
}
|
||||
|
||||
static inline bool SkColorTypeIsValid(unsigned value) {
|
||||
@ -85,7 +85,7 @@ static inline size_t SkColorTypeComputeOffset(SkColorType ct, int x, int y, size
|
||||
if (kUnknown_SkColorType == ct) {
|
||||
return 0;
|
||||
}
|
||||
return y * rowBytes + (x << SkColorTypeShiftPerPixel(ct));
|
||||
return (size_t)y * rowBytes + ((size_t)x << SkColorTypeShiftPerPixel(ct));
|
||||
}
|
||||
|
||||
static inline bool SkColorTypeIsNormalized(SkColorType ct) {
|
||||
|
@ -473,7 +473,7 @@ private:
|
||||
fReserved = false;
|
||||
} else {
|
||||
fAllocCount = std::max(count, std::max(kMinHeapAllocCount, reserveCount));
|
||||
fItemArray = (T*)sk_malloc_throw(fAllocCount, sizeof(T));
|
||||
fItemArray = (T*)sk_malloc_throw((size_t)fAllocCount, sizeof(T));
|
||||
fOwnMemory = true;
|
||||
fReserved = reserveCount > 0;
|
||||
}
|
||||
@ -523,7 +523,7 @@ private:
|
||||
}
|
||||
template <bool E = MEM_MOVE> std::enable_if_t<!E, void> move(void* dst) {
|
||||
for (int i = 0; i < fCount; ++i) {
|
||||
new (static_cast<char*>(dst) + sizeof(T) * i) T(std::move(fItemArray[i]));
|
||||
new (static_cast<char*>(dst) + sizeof(T) * (size_t)i) T(std::move(fItemArray[i]));
|
||||
fItemArray[i].~T();
|
||||
}
|
||||
}
|
||||
@ -569,7 +569,7 @@ private:
|
||||
|
||||
fAllocCount = Sk64_pin_to_s32(newAllocCount);
|
||||
SkASSERT(fAllocCount >= newCount);
|
||||
T* newItemArray = (T*)sk_malloc_throw(fAllocCount, sizeof(T));
|
||||
T* newItemArray = (T*)sk_malloc_throw((size_t)fAllocCount, sizeof(T));
|
||||
this->move(newItemArray);
|
||||
if (fOwnMemory) {
|
||||
sk_free(fItemArray);
|
||||
|
@ -372,7 +372,7 @@ private:
|
||||
SkASSERT_RELEASE( SkTFitsIn<int>(reserve) );
|
||||
|
||||
fReserve = SkTo<int>(reserve);
|
||||
fArray = (T*)sk_realloc_throw(fArray, fReserve * sizeof(T));
|
||||
fArray = (T*)sk_realloc_throw(fArray, (size_t)fReserve * sizeof(T));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -49,7 +49,7 @@ public:
|
||||
* Returns value [0...1) as an IEEE float
|
||||
*/
|
||||
float nextF() {
|
||||
unsigned int floatint = 0x3f800000 | (this->nextU() >> 9);
|
||||
int floatint = 0x3f800000 | (int)(this->nextU() >> 9);
|
||||
float f = SkBits2Float(floatint) - 1.0f;
|
||||
return f;
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ public:
|
||||
|
||||
struct Key {
|
||||
Key() : fVkFormat(VK_FORMAT_UNDEFINED), fExternalFormat(0), fConversionKey(0) {}
|
||||
Key(VkFormat vkFormat, uint64_t externalFormat, uint8_t conversionKey) {
|
||||
Key(VkFormat vkFormat, int64_t externalFormat, uint8_t conversionKey) {
|
||||
memset(this, 0, sizeof(Key));
|
||||
fVkFormat = vkFormat;
|
||||
fExternalFormat = externalFormat;
|
||||
@ -31,7 +31,7 @@ public:
|
||||
}
|
||||
|
||||
VkFormat fVkFormat;
|
||||
uint64_t fExternalFormat;
|
||||
int64_t fExternalFormat;
|
||||
uint8_t fConversionKey;
|
||||
|
||||
bool operator==(const Key& that) const {
|
||||
|
Loading…
Reference in New Issue
Block a user