Fixes Coverity issue #1473568.
Unified · Split
| @@ -100,20 +100,17 @@ static void math_binary_not_commutative(FunType pfun, const DnnLayerMathBinaryPa · 99 unmodified lines | |||
| 100 | } | 100 | } |
| 101 | int ff_dnn_load_layer_math_binary(Layer *layer, AVIOContext *model_file_context, int file_size, int operands_num) | 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 | int dnn_size = 0; | 104 | int dnn_size = 0; |
| 105 | int input_index = 0; | 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 | dnn_size += 4; | 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 | dnn_size += 4; | 111 | dnn_size += 4; |
| 115 | if (params->input0_broadcast) { | 112 | if (params.input0_broadcast) { |
| 116 | params->v = av_int2float(avio_rl32(model_file_context)); | 113 | params.v = av_int2float(avio_rl32(model_file_context)); |
| 117 | } else { | 114 | } else { |
| 118 | layer->input_operand_indexes[input_index] = (int32_t)avio_rl32(model_file_context); | 115 | layer->input_operand_indexes[input_index] = (int32_t)avio_rl32(model_file_context); |
| 119 | if (layer->input_operand_indexes[input_index] >= operands_num) { | 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 | dnn_size += 4; | 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 | dnn_size += 4; | 124 | dnn_size += 4; |
| 128 | if (params->input1_broadcast) { | 125 | if (params.input1_broadcast) { |
| 129 | params->v = av_int2float(avio_rl32(model_file_context)); | 126 | params.v = av_int2float(avio_rl32(model_file_context)); |
| 130 | } else { | 127 | } else { |
| 131 | layer->input_operand_indexes[input_index] = (int32_t)avio_rl32(model_file_context); | 128 | layer->input_operand_indexes[input_index] = (int32_t)avio_rl32(model_file_context); |
| 132 | if (layer->input_operand_indexes[input_index] >= operands_num) { | 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 | layer->output_operand_index = (int32_t)avio_rl32(model_file_context); | 136 | layer->output_operand_index = (int32_t)avio_rl32(model_file_context); |
| 140 | dnn_size += 4; | 137 | dnn_size += 4; |
| 141 | layer->params = params; | ||
| 142 | 138 | ||
| 143 | if (layer->output_operand_index >= operands_num) { | 139 | if (layer->output_operand_index >= operands_num) { |
| 144 | return 0; | 140 | return 0; |
| 145 | } | 141 | } |
| 142 | layer->params = av_memdup(¶ms, sizeof(params)); | ||
| 143 | if (!layer->params) | ||
| 144 | return 0; | ||
| 146 | 145 | ||
| 147 | return dnn_size; | 146 | return dnn_size; |
| 148 | } | 147 | } |