Commit 88cbc582 authored by Yaowu Xu's avatar Yaowu Xu Committed by Nathan Egge

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
parent 03bd210f
......@@ -514,7 +514,7 @@ unsigned char *od_ec_enc_done(od_ec_enc *enc, uint32_t *nbytes) {
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 @@ unsigned char *od_ec_enc_done(od_ec_enc *enc, uint32_t *nbytes) {
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 @@ unsigned char *od_ec_enc_done(od_ec_enc *enc, uint32_t *nbytes) {
}
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 @@ unsigned char *od_ec_enc_done(od_ec_enc *enc, uint32_t *nbytes) {
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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment