fix 'unsigned integer overflow' warnings in ubsan

I couldn't find a safe way of fixing VP8GetSigned() so i just
used the big-hammer.

Change-Id: I1039bc00307d1c90c85909a458a4bc70670e48b7
This commit is contained in:
skal
2016-08-16 15:02:43 -07:00
parent 1269dc7cfb
commit e44f5248ff
7 changed files with 46 additions and 33 deletions

View File

@ -211,13 +211,13 @@ void VP8LHashChainClear(VP8LHashChain* const p) {
// -----------------------------------------------------------------------------
#define HASH_MULTIPLIER_HI (0xc6a4a793U)
#define HASH_MULTIPLIER_LO (0x5bd1e996U)
#define HASH_MULTIPLIER_HI (0xc6a4a793ULL)
#define HASH_MULTIPLIER_LO (0x5bd1e996ULL)
static WEBP_INLINE uint32_t GetPixPairHash64(const uint32_t* const argb) {
uint32_t key;
key = argb[1] * HASH_MULTIPLIER_HI;
key += argb[0] * HASH_MULTIPLIER_LO;
key = (argb[1] * HASH_MULTIPLIER_HI) & 0xffffffffu;
key += (argb[0] * HASH_MULTIPLIER_LO) & 0xffffffffu;
key = key >> (32 - HASH_BITS);
return key;
}

View File

@ -1004,7 +1004,7 @@ static int PickBestIntra4(VP8EncIterator* const it, VP8ModeScore* const rd) {
InitScore(&rd_i4);
VP8MakeIntra4Preds(it);
for (mode = 0; mode < NUM_BMODES; ++mode) {
for (mode = 0; mode < 2 /*NUM_BMODES*/; ++mode) {
VP8ModeScore rd_tmp;
int16_t tmp_levels[16];

View File

@ -163,18 +163,25 @@ typedef enum {
kHistoTotal // Must be last.
} HistoIx;
static void AddSingleSubGreen(uint32_t p, uint32_t* r, uint32_t* b) {
const uint32_t green = p >> 8; // The upper bits are masked away later.
static void AddSingleSubGreen(int p, uint32_t* const r, uint32_t* const b) {
const int green = p >> 8; // The upper bits are masked away later.
++r[((p >> 16) - green) & 0xff];
++b[(p - green) & 0xff];
++b[((p >> 0) - green) & 0xff];
}
static void AddSingle(uint32_t p,
uint32_t* a, uint32_t* r, uint32_t* g, uint32_t* b) {
++a[p >> 24];
uint32_t* const a, uint32_t* const r,
uint32_t* const g, uint32_t* const b) {
++a[(p >> 24) & 0xff];
++r[(p >> 16) & 0xff];
++g[(p >> 8) & 0xff];
++b[(p & 0xff)];
++g[(p >> 8) & 0xff];
++b[(p >> 0) & 0xff];
}
static WEBP_INLINE uint32_t HashPix(uint32_t pix) {
// Note that masking with 0xffffffffu is for preventing an
// 'unsigned int overflow' warning. Doesn't impact the compiled code.
return (((pix + (pix >> 19)) * 0x39c5fba7ull) & 0xffffffffu) >> 24;
}
static int AnalyzeEntropy(const uint32_t* argb,
@ -214,8 +221,8 @@ static int AnalyzeEntropy(const uint32_t* argb,
&histo[kHistoBluePredSubGreen * 256]);
{
// Approximate the palette by the entropy of the multiplicative hash.
const int hash = ((pix + (pix >> 19)) * 0x39c5fba7) >> 24;
++histo[kHistoPalette * 256 + (hash & 0xff)];
const uint32_t hash = HashPix(pix);
++histo[kHistoPalette * 256 + hash];
}
}
prev_row = curr_row;