Skip to content

Commit

Permalink
Fix several coverity defects (#13321)
Browse files Browse the repository at this point in the history
* fix cov 6 OVERRUN defects

- This will resolve many OVERRUN coveirty defects

ONE-DCO-1.0-Signed-off-by: Chunseok Lee <[email protected]>

* fix cov CHECKED_RETURN(1786052)

- fix coverity CHECKED_RETURN(1786052)

ONE-DCO-1.0-Signed-off-by: Chunseok Lee <[email protected]>

* fix cov DIVIDE_BY_ZERO(1786037)

- fix coverity DIVIDE_BY_ZERO(1786037)

Signed-off-by: Chunseok Lee <[email protected]>

* fix cov FORWARD_NULL(1786018)

- it also fixes svace 144124
- fix coverity FORWARD_NULL(1786018)

ONE-DCO-1.0-Signed-off-by: Chunseok Lee <[email protected]>

* fix cov UNINIT(1780898)

- fix coverity UNINIT for wid 1780898

ONE-DCO-1.0-Signed-off-by: Chunseok Lee <[email protected]>

* fix cov OVERRUN defects

- fix 4 cov defects: 1785997, 1786023. 1786016, 1786036

ONE-DCO-1.0-Signed-off-by: Chunseok Lee <[email protected]>

---------

Signed-off-by: Chunseok Lee <[email protected]>
  • Loading branch information
chunseoklee authored Jul 1, 2024
1 parent 8ca4cda commit aecb78e
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 8 deletions.
2 changes: 1 addition & 1 deletion onert-micro/onert-micro/include/core/OMDataType.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ inline uint32_t size(OMDataType data_type)
default:
// TODO Support remaining data types.
assert(false);
return UINT32_MAX; // Avoid compiler warning.
return 1; // Avoid compiler warning.
}
}

Expand Down
4 changes: 2 additions & 2 deletions onert-micro/onert-micro/include/execute/OMRuntimeKernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ class OMRuntimeKernel
int32_t inputs_index[maxInputSize] = {-1};
int32_t outputs_index[maxOutputSize] = {-1};

uint32_t outputs_num = -1;
uint32_t inputs_num = -1;
uint32_t outputs_num = 0;
uint32_t inputs_num = 0;

const circle::Operator *first_operator = nullptr;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ inline OMStatus SpaceToDepth(const int32_t block_size,
const T *input_data,
const core::OMRuntimeShape &unextended_output_shape, T *output_data)
{
if (block_size == 0)
{
return FailedCheckCondition;
}

const core::OMRuntimeShape input_shape =
core::OMRuntimeShape::extendedShape(4, unextended_input_shape);
const core::OMRuntimeShape output_shape =
Expand Down
18 changes: 15 additions & 3 deletions onert-micro/onert-micro/src/api/onert-micro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ NNFW_STATUS nnfw_session::loadOptimizerInfo(const circle::ModelTraining *circle_
NNFW_STATUS nnfw_session::loadLossInfo(const circle::ModelTraining *circle_model)
{
assert(circle_model != nullptr);
NNFW_RETURN_ERROR_IF_NULL(circle_model);

const circle::LossFn circle_loss = circle_model->lossfn();

Expand All @@ -219,6 +220,7 @@ NNFW_STATUS nnfw_session::loadLossInfo(const circle::ModelTraining *circle_model
NNFW_STATUS nnfw_session::loadTrainableOps(const circle::ModelTraining *circle_model, int num_ops)
{
assert(circle_model != nullptr);
NNFW_RETURN_ERROR_IF_NULL(circle_model);

auto ops_list = circle_model->trainable_ops();
if (ops_list != nullptr)
Expand All @@ -245,12 +247,22 @@ NNFW_STATUS nnfw_session::loadTrainingInfo(char *buf)
continue;
data = (model->buffers()->Get(metadata->buffer()))->data()->data();
}
NNFW_RETURN_ERROR_IF_NULL(data);

const circle::ModelTraining *traininfo_model =
circle::GetModelTraining(static_cast<const void *>(data));
_config.training_context.batch_size = traininfo_model->batch_size();
loadOptimizerInfo(traininfo_model);
loadLossInfo(traininfo_model);
loadTrainableOps(traininfo_model, num_ops);
NNFW_STATUS status = loadOptimizerInfo(traininfo_model);
if (status != NNFW_STATUS_NO_ERROR)
return status;

status = loadLossInfo(traininfo_model);
if (status != NNFW_STATUS_NO_ERROR)
return status;

status = loadTrainableOps(traininfo_model, num_ops);
if (status != NNFW_STATUS_NO_ERROR)
return status;
}
return NNFW_STATUS_NO_ERROR;
}
Expand Down
4 changes: 3 additions & 1 deletion onert-micro/onert-micro/src/execute/kernels/FloorDiv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ OMStatus onert_micro::execute::execute_kernel_CircleFloorDiv(const OMExecuteArgs
// Check the denominator
for (int i = 0; i < input_shape2.flatSize(); ++i)
{
utils::checkCondition(core::utils::castInputData<float>(input_data2)[i] != 0);
status = utils::checkCondition(core::utils::castInputData<float>(input_data2)[i] != 0);
if (status != Ok)
return status;
}
// check that input and output dimensions are equal
if (input_shape1 == input_shape2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ OMStatus checkInplaceOp(core::OMRuntimeContext &context, const circle::Operator
OMStatus findInplaceOp(core::OMRuntimeStorage &storage, core::OMRuntimeContext &context,
const OMConfig &configs, bool &is_changed)
{
OMStatus status;
OMStatus status = Ok;

const core::reader::CircleOperators *operators = context.getCircleOperators();

Expand Down

0 comments on commit aecb78e

Please sign in to comment.