Add tracking of error code (#1067)
authorЮрий Новиков/AI Tools Lab /SRR/Assistant Engineer/삼성전자 <y.novikov@partner.samsung.com>
Thu, 6 Sep 2018 08:02:31 +0000 (11:02 +0300)
committerSergey Vostokov/AI Tools Lab /SRR/Staff Engineer/삼성전자 <s.vostokov@samsung.com>
Thu, 6 Sep 2018 08:02:31 +0000 (11:02 +0300)
Return value of a functions 'fstat' and 'fseek' is not checked.
The return value may indicate error code.

Signed-off-by: y.novikov <y.novikov@partner.samsung.com>
contrib/nnc/plugin/common_frontend/model_allocation.cpp
contrib/nnc/plugin/interpreter/interpreter_plugin.cpp
contrib/nnc/utils/def2src.cpp

index 592d98c..5983368 100644 (file)
@@ -18,7 +18,11 @@ ModelAllocation::ModelAllocation(std::string filename)
   }
 
   stat st{};
-  fstat(fd, &st);
+  int flag = fstat(fd, &st);
+  if (flag == -1)
+  { 
+    return;
+  }
 
   numBytes = st.st_size;
 
index 09555b9..0d56904 100644 (file)
@@ -124,7 +124,9 @@ TensorVariant InterpreterPlugin::loadInput(const Shape &shape)
   auto f = fopen(clopt::interInputData.c_str(), "rb");
   assert(f && "Cannot open file");
 
-  fseek(f, 0L, SEEK_END);
+  bool is_error = fseek(f, 0L, SEEK_END);
+  assert(!is_error);
+  (void)is_error;
   auto len = ftell(f);
   auto tensorSize = num_elements(shape) * sizeof(float);
 
index a993e0d..68b4613 100644 (file)
@@ -1,5 +1,6 @@
 #include <iostream>
 #include <fstream>
+#include <cassert>
 
 int fileToArray(std::string &source, std::string &dest, std::string arrName) {
   FILE *fs = fopen(source.c_str(), "rb");
@@ -22,7 +23,9 @@ int fileToArray(std::string &source, std::string &dest, std::string arrName) {
 
   fo << "const char " << arrName << "[] = {" << std::endl;
 
-  fseek(fs, 0, SEEK_SET);
+  bool is_error = fseek(fs, 0L, SEEK_SET);
+  assert(!is_error);
+  (void)is_error;
   size_t bytes;
   do {
     char buf[1024];