ref: 8a1fb4027345c7f36ef02bea969484018ee0693b
parent: 5cc0a364ae9bd3e3ac6248f85283cf0cfa9ab07f
author: Johann <johannkoenig@google.com>
date: Tue Jan 31 10:18:40 EST 2017
Remove UNINITIALIZED_IS_SAFE Where clang static analysis or gcc -Wmaybe-uninitialized warns of uninitialized values, assign 0 to ints, MB_MODE_COUNT to MB_PREDICTION_MODE, and B_MODE_COUNT to B_PREDICTION_MODE. Assert that the modes have been changed from the invalid value by the end of the function. Change-Id: Ib11e1ffb08f0a6fe4b6c6729dc93b83b1c4b6350
--- a/vp8/encoder/onyx_if.c
+++ b/vp8/encoder/onyx_if.c
@@ -1633,8 +1633,7 @@
cm->sharpness_level = cpi->oxcf.Sharpness;
if (cm->horiz_scale != NORMAL || cm->vert_scale != NORMAL) {
- int UNINITIALIZED_IS_SAFE(hr), UNINITIALIZED_IS_SAFE(hs);
- int UNINITIALIZED_IS_SAFE(vr), UNINITIALIZED_IS_SAFE(vs);
+ int hr, hs, vr, vs;
Scale2Ratio(cm->horiz_scale, &hr, &hs);
Scale2Ratio(cm->vert_scale, &vr, &vs);
@@ -2504,8 +2503,7 @@
/* are we resizing the image */
if (cm->horiz_scale != 0 || cm->vert_scale != 0) {
#if CONFIG_SPATIAL_RESAMPLING
- int UNINITIALIZED_IS_SAFE(hr), UNINITIALIZED_IS_SAFE(hs);
- int UNINITIALIZED_IS_SAFE(vr), UNINITIALIZED_IS_SAFE(vs);
+ int hr, hs, vr, vs;
int tmp_height;
if (cm->vert_scale == 3) {
@@ -2538,8 +2536,7 @@
*/
if (cpi->oxcf.allow_spatial_resampling &&
(cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER)) {
- int UNINITIALIZED_IS_SAFE(hr), UNINITIALIZED_IS_SAFE(hs);
- int UNINITIALIZED_IS_SAFE(vr), UNINITIALIZED_IS_SAFE(vs);
+ int hr, hs, vr, vs;
int new_width, new_height;
/* If we are below the resample DOWN watermark then scale down a
--- a/vp8/encoder/pickinter.c
+++ b/vp8/encoder/pickinter.c
@@ -8,6 +8,7 @@
* be found in the AUTHORS file in the root of the source tree.
*/
+#include <assert.h>
#include <limits.h>
#include "vpx_config.h"
#include "./vpx_dsp_rtcd.h"
@@ -299,8 +300,8 @@
MODE_INFO *const mic = xd->mode_info_context;
const int mis = xd->mode_info_stride;
- B_PREDICTION_MODE UNINITIALIZED_IS_SAFE(best_mode);
- int UNINITIALIZED_IS_SAFE(r), UNINITIALIZED_IS_SAFE(d);
+ B_PREDICTION_MODE best_mode = B_MODE_COUNT;
+ int r = 0, d = 0;
if (mb->e_mbd.frame_type == KEY_FRAME) {
const B_PREDICTION_MODE A = above_block_mode(mic, i, mis);
@@ -313,6 +314,7 @@
cost += r;
distortion += d;
+ assert(best_mode != B_MODE_COUNT);
mic->bmi[i].as_mode = best_mode;
/* Break out case where we have already exceeded best so far value
@@ -353,7 +355,7 @@
int Vaverage = 0;
int diff;
int pred_error[4] = { 0, 0, 0, 0 }, best_error = INT_MAX;
- MB_PREDICTION_MODE UNINITIALIZED_IS_SAFE(best_mode);
+ MB_PREDICTION_MODE best_mode = MB_MODE_COUNT;
for (i = 0; i < 8; ++i) {
uleft_col[i] = x->dst.u_buffer[i * x->dst.uv_stride - 1];
@@ -442,6 +444,7 @@
}
}
+ assert(best_mode != MB_MODE_COUNT);
mb->e_mbd.mode_info_context->mbmi.uv_mode = best_mode;
}
--- a/vp8/encoder/rdopt.c
+++ b/vp8/encoder/rdopt.c
@@ -8,6 +8,7 @@
* be found in the AUTHORS file in the root of the source tree.
*/
+#include <assert.h>
#include <stdio.h>
#include <math.h>
#include <limits.h>
@@ -608,9 +609,8 @@
for (i = 0; i < 16; ++i) {
MODE_INFO *const mic = xd->mode_info_context;
const int mis = xd->mode_info_stride;
- B_PREDICTION_MODE UNINITIALIZED_IS_SAFE(best_mode);
- int UNINITIALIZED_IS_SAFE(r), UNINITIALIZED_IS_SAFE(ry),
- UNINITIALIZED_IS_SAFE(d);
+ B_PREDICTION_MODE best_mode = B_MODE_COUNT;
+ int r = 0, ry = 0, d = 0;
if (mb->e_mbd.frame_type == KEY_FRAME) {
const B_PREDICTION_MODE A = above_block_mode(mic, i, mis);
@@ -627,6 +627,7 @@
distortion += d;
tot_rate_y += ry;
+ assert(best_mode != B_MODE_COUNT);
mic->bmi[i].as_mode = best_mode;
if (total_rd >= (int64_t)best_rd) break;
@@ -644,7 +645,7 @@
static int rd_pick_intra16x16mby_mode(MACROBLOCK *x, int *Rate, int *rate_y,
int *Distortion) {
MB_PREDICTION_MODE mode;
- MB_PREDICTION_MODE UNINITIALIZED_IS_SAFE(mode_selected);
+ MB_PREDICTION_MODE mode_selected = MB_MODE_COUNT;
int rate, ratey;
int distortion;
int best_rd = INT_MAX;
@@ -674,6 +675,7 @@
}
}
+ assert(mode_selected != MB_MODE_COUNT);
xd->mode_info_context->mbmi.mode = mode_selected;
return best_rd;
}
@@ -741,9 +743,9 @@
static void rd_pick_intra_mbuv_mode(MACROBLOCK *x, int *rate,
int *rate_tokenonly, int *distortion) {
MB_PREDICTION_MODE mode;
- MB_PREDICTION_MODE UNINITIALIZED_IS_SAFE(mode_selected);
+ MB_PREDICTION_MODE mode_selected = MB_MODE_COUNT;
int best_rd = INT_MAX;
- int UNINITIALIZED_IS_SAFE(d), UNINITIALIZED_IS_SAFE(r);
+ int d = 0, r = 0;
int rate_to;
MACROBLOCKD *xd = &x->e_mbd;
@@ -787,6 +789,7 @@
*rate = r;
*distortion = d;
+ assert(mode_selected != MB_MODE_COUNT);
xd->mode_info_context->mbmi.uv_mode = mode_selected;
}
--- a/vpx_ports/mem.h
+++ b/vpx_ports/mem.h
@@ -23,16 +23,6 @@
#define DECLARE_ALIGNED(n, typ, val) typ val
#endif
-/* Indicates that the usage of the specified variable has been audited to assure
- * that it's safe to use uninitialized. Silences 'may be used uninitialized'
- * warnings on gcc.
- */
-#if defined(__GNUC__) && __GNUC__
-#define UNINITIALIZED_IS_SAFE(x) x = x
-#else
-#define UNINITIALIZED_IS_SAFE(x) x
-#endif
-
#if HAVE_NEON && defined(_MSC_VER)
#define __builtin_prefetch(x)
#endif