[Filesystem] Fix for reading binary data 74/187674/1
authorSzymon Jastrzebski <s.jastrzebsk@partner.samsung.com>
Mon, 27 Aug 2018 07:24:18 +0000 (09:24 +0200)
committerSzymon Jastrzebski <s.jastrzebsk@partner.samsung.com>
Mon, 27 Aug 2018 10:48:47 +0000 (12:48 +0200)
+ The variable 'size' wasn't initialized.

[Verification] TCT TV&Mobile 100%

Change-Id: I803ac19cc964e1bd3d54f5fb403b348ec2779734
Signed-off-by: Szymon Jastrzebski <s.jastrzebsk@partner.samsung.com>
src/filesystem/filesystem_instance.cc

index 5096ed18c582fee89e8fedd0678a919efe3261b6..e297ce51856ace7fcc0943b688c014532f1d83d5 100644 (file)
@@ -2169,23 +2169,20 @@ void FilesystemInstance::FileHandleReadData(const picojson::value& args, picojso
   }
 
   size_t size;
-  if (args.contains("size")) {
-    // If user passed 'size' parameter, we need to read at most 'size' bytes.
-    double size_double = args.get("size").get<double>();
-    if (std::string::npos <= static_cast<unsigned long long>(size_double)) {
-      LogAndReportError(InvalidValuesException("Invalid size was given"), out);
-      return;
-    }
-    size = static_cast<size_t>(size_double);
-  }
-
   // We need to check how many bytes is it possible to read until the EOF.
   try {
     // We need to read from file exactly the minimum value of 'size' given by user and the
-    // 'possible_bytes_to_read' to avoid returning array with redundant data
-    // (which would be equal to 0).
-    size_t possible_bytes_to_read = file_bytes_to_eof(fh->second->file_handle);
-    size = std::min(size, possible_bytes_to_read);
+    // 'size ' to avoid returning array with redundant data (which would be equal to 0).
+    size = file_bytes_to_eof(fh->second->file_handle);
+    if (args.contains("size")) {
+      // If user passed 'size' parameter, we need to read at most 'size' bytes.
+      double size_double = args.get("size").get<double>();
+      if (std::string::npos <= static_cast<unsigned long long>(size_double)) {
+        LogAndReportError(InvalidValuesException("Invalid size was given"), out);
+        return;
+      }
+      size = std::min(static_cast<size_t>(size_double), size);
+    }
   } catch (const std::system_error& e) {
     LogAndReportError(IOException(e.what()), out);
     return;