From: Szymon Jastrzebski Date: Mon, 27 Aug 2018 07:24:18 +0000 (+0200) Subject: [Filesystem] Fix for reading binary data X-Git-Tag: submit/tizen/20180907.104919~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F74%2F187674%2F1;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [Filesystem] Fix for reading binary data + The variable 'size' wasn't initialized. [Verification] TCT TV&Mobile 100% Change-Id: I803ac19cc964e1bd3d54f5fb403b348ec2779734 Signed-off-by: Szymon Jastrzebski --- diff --git a/src/filesystem/filesystem_instance.cc b/src/filesystem/filesystem_instance.cc index 5096ed18..e297ce51 100644 --- a/src/filesystem/filesystem_instance.cc +++ b/src/filesystem/filesystem_instance.cc @@ -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(); - if (std::string::npos <= static_cast(size_double)) { - LogAndReportError(InvalidValuesException("Invalid size was given"), out); - return; - } - size = static_cast(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(); + if (std::string::npos <= static_cast(size_double)) { + LogAndReportError(InvalidValuesException("Invalid size was given"), out); + return; + } + size = std::min(static_cast(size_double), size); + } } catch (const std::system_error& e) { LogAndReportError(IOException(e.what()), out); return;