[svace] fix svace issues
authorSeungbaek Hong <sb92.hong@samsung.com>
Wed, 27 Mar 2024 09:44:06 +0000 (18:44 +0900)
committerjijoong.moon <jijoong.moon@samsung.com>
Thu, 28 Mar 2024 23:46:06 +0000 (08:46 +0900)
fixed all svace issues on main branch

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

Change-Id: I507379b2ee5f4d15c306408efb56347afaba23ba
Signed-off-by: Seungbaek Hong <sb92.hong@samsung.com>
Applications/utils/jni/bitmap_helpers.cpp
nntrainer/dataset/raw_file_data_producer.cpp
nntrainer/layers/gru.cpp
nntrainer/layers/lstm.cpp
nntrainer/layers/rnn.cpp
nntrainer/utils/util_func.cpp

index ba01344..0fc64ac 100644 (file)
@@ -13,6 +13,8 @@ See the License for the specific language governing permissions and
 limitations under the License.
 @file  bitmat_helpers.cpp
 @brief  bitmap_helpers from tensorflow
+@author TensorFlow Authors
+@bug there are no known bugs
 
 ==============================================================================*/
 
@@ -89,7 +91,7 @@ uint8_t *read_bmp(const std::string &input_bmp_name, int *width, int *height,
 
   const uint8_t *img_bytes = new uint8_t[len];
   file.seekg(0, std::ios::beg);
-  file.read((char *)img_bytes, len);
+  file.read((char *)img_bytes, static_cast<std::streamsize>(len));
   const int32_t header_size =
     *(reinterpret_cast<const int32_t *>(img_bytes + 10));
   *width = *(reinterpret_cast<const int32_t *>(img_bytes + 18));
index e8ce12e..5a51139 100644 (file)
@@ -67,8 +67,9 @@ RawFileDataProducer::finalize(const std::vector<TensorDim> &input_dims,
                                  std::vector<Tensor> &labels) {
     NNTR_THROW_IF(idx >= sz, std::range_error)
       << "given index is out of bound, index: " << idx << " size: " << sz;
-    file.seekg(idx * sample_size * RawFileDataProducer::pixel_size,
-               std::ios_base::beg);
+    std::streamoff offset = static_cast<std::streamoff>(
+      idx * sample_size * RawFileDataProducer::pixel_size);
+    file.seekg(offset, std::ios_base::beg);
     for (auto &input : inputs) {
       input.read(file);
     }
@@ -107,7 +108,8 @@ RawFileDataProducer::size(const std::vector<TensorDim> &input_dims,
   //   << " Given file does not align with the given sample size, sample size: "
   //   << sample_size << " file_size: " << file_size;
 
-  return file_size / (sample_size * RawFileDataProducer::pixel_size);
+  return static_cast<unsigned int>(file_size) /
+         (sample_size * RawFileDataProducer::pixel_size);
 }
 
 void RawFileDataProducer::exportTo(
index 8f68cb5..1b90247 100644 (file)
@@ -94,6 +94,8 @@ void GRULayer::finalize(InitLayerContext &context) {
   const TensorDim &input_dim = context.getInputDimensions()[0];
   const unsigned int batch_size = input_dim.batch();
   const unsigned int max_timestep = input_dim.height();
+  NNTR_THROW_IF(max_timestep < 1, std::runtime_error)
+    << "max timestep must be greator than 0 in gru layer.";
   const unsigned int feature_size = input_dim.width();
 
   // if return_sequences == False :
index bc3d750..79a3a28 100644 (file)
@@ -424,6 +424,8 @@ void LSTMLayer::finalize(InitLayerContext &context) {
   if (!std::get<props::MaxTimestep>(lstm_props).empty())
     max_timestep =
       std::max(max_timestep, std::get<props::MaxTimestep>(lstm_props).get());
+  NNTR_THROW_IF(max_timestep < 1, std::runtime_error)
+    << "max timestep must be greator than 0 in lstm layer.";
   std::get<props::MaxTimestep>(lstm_props).set(max_timestep);
   const unsigned int feature_size = input_dim.width();
 
index 8ac74bd..e5fb70a 100644 (file)
@@ -77,6 +77,8 @@ void RNNLayer::finalize(InitLayerContext &context) {
   const TensorDim &input_dim = context.getInputDimensions()[SINGLE_INOUT_IDX];
   const unsigned int batch_size = input_dim.batch();
   const unsigned int max_timestep = input_dim.height();
+  NNTR_THROW_IF(max_timestep < 1, std::runtime_error)
+    << "max timestep must be greator than 0 in rnn layer.";
   const unsigned int feature_size = input_dim.width();
 
   // output_dim = [ batch, 1, (return_sequences ? time_iteration : 1), unit ]
index fe212a4..207a810 100644 (file)
@@ -214,7 +214,8 @@ char *getRealpath(const char *name, char *resolved) {
 #ifdef _WIN32
   return _fullpath(resolved, name, MAX_PATH_LENGTH);
 #else
-  return realpath(name, resolved);
+  resolved = realpath(name, nullptr);
+  return resolved;
 #endif
 }