[automerger skipped] DO NOT MERGE - Merge PPRL.190405.003 into stage-aosp-master
am: 32f06593ed -s ours
am skip reason: subject contains skip directive
Change-Id: Ic7bde3602d31d3901d5fcf26d64b0419b5c6b30e
diff --git a/Android.bp b/Android.bp
index 080b563..6d33c66 100644
--- a/Android.bp
+++ b/Android.bp
@@ -65,4 +65,9 @@
export_include_dirs: ["."],
shared_libs: ["liblog"],
+
+ sanitize: {
+ integer_overflow: true,
+ misc_undefined: ["bounds"],
+ },
}
diff --git a/Tremolo/codebook.c b/Tremolo/codebook.c
index a06302d..8948cf3 100644
--- a/Tremolo/codebook.c
+++ b/Tremolo/codebook.c
@@ -825,12 +825,21 @@
}
add <<= shiftM;
- for(i=0;i<s->dim;i++)
- v[i]= ((add + v[i] * mul) >> shiftM);
+ ogg_int32_t tmp;
+ for(i=0;i<s->dim;i++) {
+ if (__builtin_mul_overflow(v[i], mul, &tmp) ||
+ __builtin_add_overflow(tmp, add, &tmp)) {
+ return -1;
+ }
+ v[i] = tmp >> shiftM;
+ }
if(s->q_seq)
- for(i=1;i<s->dim;i++)
- v[i]+=v[i-1];
+ for(i=1;i<s->dim;i++) {
+ if (__builtin_add_overflow(v[i], v[i-1], &v[i])) {
+ return -1;
+ }
+ }
}
return 0;