Fixes Coverity issue #1473568.
Showing the changes to libavfilter (1 of 1 file). Show all
Unified · Split
| @@ -100,20 +100,17 @@ static void math_binary_not_commutative(FunType pfun, const DnnLayerMathBinaryPa · 99 unmodified lines | ||
| 100 | 100 | } |
| 101 | 101 | int ff_dnn_load_layer_math_binary(Layer *layer, AVIOContext *model_file_context, int file_size, int operands_num) |
| 102 | 102 | { |
| 103 | − DnnLayerMathBinaryParams *params; | |
| 103 | + DnnLayerMathBinaryParams params = { 0 }; | |
| 104 | 104 | int dnn_size = 0; |
| 105 | 105 | int input_index = 0; |
| 106 | − params = av_malloc(sizeof(*params)); | |
| 107 | − if (!params) | |
| 108 | − return 0; | |
| 109 | 106 | |
| 110 | − params->bin_op = (int32_t)avio_rl32(model_file_context); | |
| 107 | + params.bin_op = (int32_t)avio_rl32(model_file_context); | |
| 111 | 108 | dnn_size += 4; |
| 112 | 109 | |
| 113 | − params->input0_broadcast = (int32_t)avio_rl32(model_file_context); | |
| 110 | + params.input0_broadcast = (int32_t)avio_rl32(model_file_context); | |
| 114 | 111 | dnn_size += 4; |
| 115 | − if (params->input0_broadcast) { | |
| 116 | − params->v = av_int2float(avio_rl32(model_file_context)); | |
| 112 | + if (params.input0_broadcast) { | |
| 113 | + params.v = av_int2float(avio_rl32(model_file_context)); | |
| 117 | 114 | } else { |
| 118 | 115 | layer->input_operand_indexes[input_index] = (int32_t)avio_rl32(model_file_context); |
| 119 | 116 | if (layer->input_operand_indexes[input_index] >= operands_num) { |
| @@ -123,10 +120,10 @@ int ff_dnn_load_layer_math_binary(Layer *layer, AVIOContext *model_file_context, · 3 unmodified lines | ||
| 123 | 120 | } |
| 124 | 121 | dnn_size += 4; |
| 125 | 122 | |
| 126 | − params->input1_broadcast = (int32_t)avio_rl32(model_file_context); | |
| 123 | + params.input1_broadcast = (int32_t)avio_rl32(model_file_context); | |
| 127 | 124 | dnn_size += 4; |
| 128 | − if (params->input1_broadcast) { | |
| 129 | − params->v = av_int2float(avio_rl32(model_file_context)); | |
| 125 | + if (params.input1_broadcast) { | |
| 126 | + params.v = av_int2float(avio_rl32(model_file_context)); | |
| 130 | 127 | } else { |
| 131 | 128 | layer->input_operand_indexes[input_index] = (int32_t)avio_rl32(model_file_context); |
| 132 | 129 | if (layer->input_operand_indexes[input_index] >= operands_num) { |
| @@ -138,11 +135,13 @@ int ff_dnn_load_layer_math_binary(Layer *layer, AVIOContext *model_file_context, · 5 unmodified lines | ||
| 138 | 135 | |
| 139 | 136 | layer->output_operand_index = (int32_t)avio_rl32(model_file_context); |
| 140 | 137 | dnn_size += 4; |
| 141 | − layer->params = params; | |
| 142 | 138 | |
| 143 | 139 | if (layer->output_operand_index >= operands_num) { |
| 144 | 140 | return 0; |
| 145 | 141 | } |
| 142 | + layer->params = av_memdup(¶ms, sizeof(params)); | |
| 143 | + if (!layer->params) | |
| 144 | + return 0; | |
| 146 | 145 | |
| 147 | 146 | return dnn_size; |
| 148 | 147 | } |