Skip to content

Commit

Permalink
[coverity] fix coverity issue
Browse files Browse the repository at this point in the history
This PR resolves the issue by checking what the malloc function returned

**Self-evaluation:**
1. Build test: [X]Passed [ ]Failed [ ]Skipped
2. Run test:   [X]Passed [ ]Failed [ ]Skipped

Signed-off-by: Donghyeon Jeong <[email protected]>
  • Loading branch information
djeong20 committed Sep 25, 2024
1 parent 8104cbe commit f3560cb
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions nntrainer/tensor/blas_neon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ void sgemv_transpose(const float *A, const float *X, float *Y, uint32_t rows,
if (cols % 16 == 0) {
unsigned int n = cols / 16;
bool *initialized = (bool *)malloc(sizeof(bool) * n);

NNTR_THROW_IF(initialized == nullptr, std::invalid_argument)
<< "Error: Memory allocation failed.";

unsigned int step;
for (unsigned int i = 0; i < cols / 16; ++i) {
initialized[i] = false;
Expand Down Expand Up @@ -198,6 +202,10 @@ void sgemv_transpose(const float *A, const float *X, float *Y, uint32_t rows,
} else if (cols % 8 == 0) {
unsigned int n = cols / 8;
bool *initialized = (bool *)malloc(sizeof(bool) * n);

NNTR_THROW_IF(initialized == nullptr, std::invalid_argument)
<< "Error: Memory allocation failed.";

unsigned int step;
for (unsigned int i = 0; i < cols / 8; ++i) {
initialized[i] = false;
Expand Down Expand Up @@ -240,6 +248,9 @@ void sgemv_transpose(const float *A, const float *X, float *Y, uint32_t rows,
unsigned int n = cols / 4;
bool *initialized = (bool *)malloc(sizeof(bool) * n);

NNTR_THROW_IF(initialized == nullptr, std::invalid_argument)
<< "Error: Memory allocation failed.";

unsigned int step;
for (unsigned int i = 0; i < cols / 4; ++i) {
initialized[i] = false;
Expand Down

0 comments on commit f3560cb

Please sign in to comment.