[coverity] fix coverity issue
authorDonghyeon Jeong <dhyeon.jeong@samsung.com>
Wed, 25 Sep 2024 07:35:36 +0000 (16:35 +0900)
committerJijoong Moon <jijoong.moon@samsung.com>
Wed, 16 Oct 2024 00:00:30 +0000 (09:00 +0900)
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 <dhyeon.jeong@samsung.com>
nntrainer/tensor/blas_neon.cpp

index 4b6c05c72ea8a399b97e884bb7667b6de33ce696..89ffddfa770b6a2f9233e3e531b7d13f5fd60dd1 100644 (file)
@@ -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;