ref: 4aac819a1838d1674ce2483801ee98d411b63d29
parent: 185836116cb77ded17f0d2e251307db1ee27132b
author: Debargha Mukherjee <[email protected]>
date: Wed Mar 30 09:53:37 EDT 2016
Fix some static analysis issues with resize Change-Id: I2e8ada1ae95bd5577344d6f898e6ad4723e38fbd
--- a/vp10/encoder/resize.c
+++ b/vp10/encoder/resize.c
@@ -445,7 +445,7 @@
int length,
uint8_t *output,
int olength,
- uint8_t *buf) {
+ uint8_t *otmp) {
int steps;
if (length == olength) {
memcpy(output, input, sizeof(output[0]) * length);
@@ -456,16 +456,10 @@
if (steps > 0) {
int s;
uint8_t *out = NULL;
- uint8_t *tmpbuf = NULL;
- uint8_t *otmp, *otmp2;
+ uint8_t *otmp2;
int filteredlength = length;
- if (!tmpbuf) {
- tmpbuf = (uint8_t *)malloc(sizeof(uint8_t) * length);
- if (tmpbuf == NULL) return;
- otmp = tmpbuf;
- } else {
- otmp = buf;
- }
+
+ assert(otmp != NULL);
otmp2 = otmp + get_down2_length(length, 1);
for (s = 0; s < steps; ++s) {
const int proj_filteredlength = get_down2_length(filteredlength, 1);
@@ -483,8 +477,6 @@
if (filteredlength != olength) {
interpolate(out, filteredlength, output, olength);
}
- if (tmpbuf)
- free(tmpbuf);
} else {
interpolate(input, length, output, olength);
}
@@ -520,8 +512,11 @@
uint8_t *intbuf = (uint8_t *)malloc(sizeof(uint8_t) * width2 * height);
uint8_t *tmpbuf = (uint8_t *)malloc(sizeof(uint8_t) *
(width < height ? height : width));
- uint8_t *arrbuf = (uint8_t *)malloc(sizeof(uint8_t) * (height + height2));
- if (intbuf == NULL || tmpbuf == NULL || arrbuf == NULL) goto Error;
+ uint8_t *arrbuf = (uint8_t *)malloc(sizeof(uint8_t) * height);
+ uint8_t *arrbuf2 = (uint8_t *)malloc(sizeof(uint8_t) * height2);
+ if (intbuf == NULL || tmpbuf == NULL ||
+ arrbuf == NULL || arrbuf2 == NULL)
+ goto Error;
assert(width > 0);
assert(height > 0);
assert(width2 > 0);
@@ -531,8 +526,8 @@
intbuf + width2 * i, width2, tmpbuf);
for (i = 0; i < width2; ++i) {
fill_col_to_arr(intbuf + i, width2, height, arrbuf);
- resize_multistep(arrbuf, height, arrbuf + height, height2, tmpbuf);
- fill_arr_to_col(output + i, out_stride, height2, arrbuf + height);
+ resize_multistep(arrbuf, height, arrbuf2, height2, tmpbuf);
+ fill_arr_to_col(output + i, out_stride, height2, arrbuf2);
}
Error:
@@ -539,6 +534,7 @@
free(intbuf);
free(tmpbuf);
free(arrbuf);
+ free(arrbuf2);
}
#if CONFIG_VP9_HIGHBITDEPTH
@@ -741,7 +737,7 @@
int length,
uint16_t *output,
int olength,
- uint16_t *buf,
+ uint16_t *otmp,
int bd) {
int steps;
if (length == olength) {
@@ -753,16 +749,10 @@
if (steps > 0) {
int s;
uint16_t *out = NULL;
- uint16_t *tmpbuf = NULL;
- uint16_t *otmp, *otmp2;
+ uint16_t *otmp2;
int filteredlength = length;
- if (!tmpbuf) {
- tmpbuf = (uint16_t *)malloc(sizeof(uint16_t) * length);
- if (tmpbuf == NULL) return;
- otmp = tmpbuf;
- } else {
- otmp = buf;
- }
+
+ assert(otmp != NULL);
otmp2 = otmp + get_down2_length(length, 1);
for (s = 0; s < steps; ++s) {
const int proj_filteredlength = get_down2_length(filteredlength, 1);
@@ -780,8 +770,6 @@
if (filteredlength != olength) {
highbd_interpolate(out, filteredlength, output, olength, bd);
}
- if (tmpbuf)
- free(tmpbuf);
} else {
highbd_interpolate(input, length, output, olength, bd);
}
@@ -820,8 +808,10 @@
uint16_t *intbuf = (uint16_t *)malloc(sizeof(uint16_t) * width2 * height);
uint16_t *tmpbuf = (uint16_t *)malloc(sizeof(uint16_t) *
(width < height ? height : width));
- uint16_t *arrbuf = (uint16_t *)malloc(sizeof(uint16_t) * (height + height2));
- if (intbuf == NULL || tmpbuf == NULL || arrbuf == NULL) goto Error;
+ uint16_t *arrbuf = (uint16_t *)malloc(sizeof(uint16_t) * height);
+ uint16_t *arrbuf2 = (uint16_t *)malloc(sizeof(uint16_t) * height2);
+ if (intbuf == NULL || tmpbuf == NULL ||
+ arrbuf == NULL || arrbuf2 == NULL) goto Error;
for (i = 0; i < height; ++i) {
highbd_resize_multistep(CONVERT_TO_SHORTPTR(input + in_stride * i), width,
intbuf + width2 * i, width2, tmpbuf, bd);
@@ -828,10 +818,10 @@
}
for (i = 0; i < width2; ++i) {
highbd_fill_col_to_arr(intbuf + i, width2, height, arrbuf);
- highbd_resize_multistep(arrbuf, height, arrbuf + height, height2, tmpbuf,
+ highbd_resize_multistep(arrbuf, height, arrbuf2, height2, tmpbuf,
bd);
highbd_fill_arr_to_col(CONVERT_TO_SHORTPTR(output + i), out_stride, height2,
- arrbuf + height);
+ arrbuf2);
}
Error:
@@ -838,6 +828,7 @@
free(intbuf);
free(tmpbuf);
free(arrbuf);
+ free(arrbuf2);
}
#endif // CONFIG_VP9_HIGHBITDEPTH
--- a/vp9/encoder/vp9_resize.c
+++ b/vp9/encoder/vp9_resize.c
@@ -446,7 +446,7 @@
int length,
uint8_t *output,
int olength,
- uint8_t *buf) {
+ uint8_t *otmp) {
int steps;
if (length == olength) {
memcpy(output, input, sizeof(output[0]) * length);
@@ -457,16 +457,10 @@
if (steps > 0) {
int s;
uint8_t *out = NULL;
- uint8_t *tmpbuf = NULL;
- uint8_t *otmp, *otmp2;
+ uint8_t *otmp2;
int filteredlength = length;
- if (!tmpbuf) {
- tmpbuf = (uint8_t *)malloc(sizeof(uint8_t) * length);
- if (tmpbuf == NULL) return;
- otmp = tmpbuf;
- } else {
- otmp = buf;
- }
+
+ assert(otmp != NULL);
otmp2 = otmp + get_down2_length(length, 1);
for (s = 0; s < steps; ++s) {
const int proj_filteredlength = get_down2_length(filteredlength, 1);
@@ -484,8 +478,6 @@
if (filteredlength != olength) {
interpolate(out, filteredlength, output, olength);
}
- if (tmpbuf)
- free(tmpbuf);
} else {
interpolate(input, length, output, olength);
}
@@ -521,8 +513,11 @@
uint8_t *intbuf = (uint8_t *)malloc(sizeof(uint8_t) * width2 * height);
uint8_t *tmpbuf = (uint8_t *)malloc(sizeof(uint8_t) *
(width < height ? height : width));
- uint8_t *arrbuf = (uint8_t *)malloc(sizeof(uint8_t) * (height + height2));
- if (intbuf == NULL || tmpbuf == NULL || arrbuf == NULL) goto Error;
+ uint8_t *arrbuf = (uint8_t *)malloc(sizeof(uint8_t) * height);
+ uint8_t *arrbuf2 = (uint8_t *)malloc(sizeof(uint8_t) * height2);
+ if (intbuf == NULL || tmpbuf == NULL ||
+ arrbuf == NULL || arrbuf2 == NULL)
+ goto Error;
assert(width > 0);
assert(height > 0);
assert(width2 > 0);
@@ -529,11 +524,11 @@
assert(height2 > 0);
for (i = 0; i < height; ++i)
resize_multistep(input + in_stride * i, width,
- intbuf + width2 * i, width2, tmpbuf);
+ intbuf + width2 * i, width2, tmpbuf);
for (i = 0; i < width2; ++i) {
fill_col_to_arr(intbuf + i, width2, height, arrbuf);
- resize_multistep(arrbuf, height, arrbuf + height, height2, tmpbuf);
- fill_arr_to_col(output + i, out_stride, height2, arrbuf + height);
+ resize_multistep(arrbuf, height, arrbuf2, height2, tmpbuf);
+ fill_arr_to_col(output + i, out_stride, height2, arrbuf2);
}
Error:
@@ -540,6 +535,7 @@
free(intbuf);
free(tmpbuf);
free(arrbuf);
+ free(arrbuf2);
}
#if CONFIG_VP9_HIGHBITDEPTH
@@ -742,7 +738,7 @@
int length,
uint16_t *output,
int olength,
- uint16_t *buf,
+ uint16_t *otmp,
int bd) {
int steps;
if (length == olength) {
@@ -754,16 +750,10 @@
if (steps > 0) {
int s;
uint16_t *out = NULL;
- uint16_t *tmpbuf = NULL;
- uint16_t *otmp, *otmp2;
+ uint16_t *otmp2;
int filteredlength = length;
- if (!tmpbuf) {
- tmpbuf = (uint16_t *)malloc(sizeof(uint16_t) * length);
- if (tmpbuf == NULL) return;
- otmp = tmpbuf;
- } else {
- otmp = buf;
- }
+
+ assert(otmp != NULL);
otmp2 = otmp + get_down2_length(length, 1);
for (s = 0; s < steps; ++s) {
const int proj_filteredlength = get_down2_length(filteredlength, 1);
@@ -781,8 +771,6 @@
if (filteredlength != olength) {
highbd_interpolate(out, filteredlength, output, olength, bd);
}
- if (tmpbuf)
- free(tmpbuf);
} else {
highbd_interpolate(input, length, output, olength, bd);
}
@@ -821,8 +809,11 @@
uint16_t *intbuf = (uint16_t *)malloc(sizeof(uint16_t) * width2 * height);
uint16_t *tmpbuf = (uint16_t *)malloc(sizeof(uint16_t) *
(width < height ? height : width));
- uint16_t *arrbuf = (uint16_t *)malloc(sizeof(uint16_t) * (height + height2));
- if (intbuf == NULL || tmpbuf == NULL || arrbuf == NULL) goto Error;
+ uint16_t *arrbuf = (uint16_t *)malloc(sizeof(uint16_t) * height);
+ uint16_t *arrbuf2 = (uint16_t *)malloc(sizeof(uint16_t) * height2);
+ if (intbuf == NULL || tmpbuf == NULL ||
+ arrbuf == NULL || arrbuf2 == NULL)
+ goto Error;
for (i = 0; i < height; ++i) {
highbd_resize_multistep(CONVERT_TO_SHORTPTR(input + in_stride * i), width,
intbuf + width2 * i, width2, tmpbuf, bd);
@@ -829,10 +820,10 @@
}
for (i = 0; i < width2; ++i) {
highbd_fill_col_to_arr(intbuf + i, width2, height, arrbuf);
- highbd_resize_multistep(arrbuf, height, arrbuf + height, height2, tmpbuf,
+ highbd_resize_multistep(arrbuf, height, arrbuf2, height2, tmpbuf,
bd);
highbd_fill_arr_to_col(CONVERT_TO_SHORTPTR(output + i), out_stride, height2,
- arrbuf + height);
+ arrbuf2);
}
Error:
@@ -839,6 +830,7 @@
free(intbuf);
free(tmpbuf);
free(arrbuf);
+ free(arrbuf2);
}
#endif // CONFIG_VP9_HIGHBITDEPTH