Use an alternative fix to ubsan warning.
This commit revert the previous fix of the ubsan warning for unsigned
int overflow, and use a better fix by moving the offs-- inside the
while loop to avoid "0-1" situation.
Change-Id: Id4a3e03859ebcdf264df0808412b30841028f87c
diff --git a/aom_dsp/entenc.c b/aom_dsp/entenc.c
index 214f183..1d1a6bc 100644
--- a/aom_dsp/entenc.c
+++ b/aom_dsp/entenc.c
@@ -514,7 +514,7 @@
unsigned char *out;
uint32_t storage;
uint16_t *buf;
- int offs;
+ uint32_t offs;
uint32_t end_offs;
int nend_bits;
od_ec_window m;
@@ -554,7 +554,7 @@
if (s > 0) {
unsigned n;
storage = enc->precarry_storage;
- if (offs + ((s + 7) >> 3) > (int)storage) {
+ if (offs + ((s + 7) >> 3) > storage) {
storage = storage * 2 + ((s + 7) >> 3);
buf = (uint16_t *)realloc(buf, sizeof(*buf) * storage);
if (buf == NULL) {
@@ -566,7 +566,7 @@
}
n = (1 << (c + 16)) - 1;
do {
- OD_ASSERT(offs < (int)storage);
+ OD_ASSERT(offs < storage);
buf[offs++] = (uint16_t)(e >> (c + 16));
e &= n;
s -= 8;
@@ -607,7 +607,8 @@
out = out + storage - (offs + end_offs);
c = 0;
end_offs = offs;
- while (offs-- > 0) {
+ while (offs > 0) {
+ offs--;
c = buf[offs] + c;
out[offs] = (unsigned char)c;
c >>= 8;