From f3560cbac1159a1b710fadd7e71c3f39dd95cbd0 Mon Sep 17 00:00:00 2001 From: Donghyeon Jeong Date: Wed, 25 Sep 2024 16:35:36 +0900 Subject: [PATCH] [coverity] fix coverity issue 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 --- nntrainer/tensor/blas_neon.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/nntrainer/tensor/blas_neon.cpp b/nntrainer/tensor/blas_neon.cpp index 4b6c05c72e..89ffddfa77 100644 --- a/nntrainer/tensor/blas_neon.cpp +++ b/nntrainer/tensor/blas_neon.cpp @@ -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; @@ -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; @@ -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;