arrow-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From w...@apache.org
Subject arrow git commit: ARROW-742: [C++] std::wstring_convert exceptions handling
Date Tue, 13 Jun 2017 01:13:28 GMT
Repository: arrow
Updated Branches:
  refs/heads/master ac6485390 -> 2a2b1094e


ARROW-742: [C++] std::wstring_convert exceptions handling

Author: Max Risuhin <risuhin.max@gmail.com>

Closes #749 from MaxRis/ARROW-742 and squashes the following commits:

5479b3f4 [Max Risuhin] ARROW-742: [C++] std::wstring_convert exceptions handling


Project: http://git-wip-us.apache.org/repos/asf/arrow/repo
Commit: http://git-wip-us.apache.org/repos/asf/arrow/commit/2a2b1094
Tree: http://git-wip-us.apache.org/repos/asf/arrow/tree/2a2b1094
Diff: http://git-wip-us.apache.org/repos/asf/arrow/diff/2a2b1094

Branch: refs/heads/master
Commit: 2a2b1094e5370956917351ed49cf914ee2d5301f
Parents: ac64853
Author: Max Risuhin <risuhin.max@gmail.com>
Authored: Mon Jun 12 21:13:22 2017 -0400
Committer: Wes McKinney <wes.mckinney@twosigma.com>
Committed: Mon Jun 12 21:13:22 2017 -0400

----------------------------------------------------------------------
 cpp/src/arrow/io/file.cc         | 14 +++++++++++---
 cpp/src/arrow/io/io-file-test.cc | 12 ++++++++++++
 2 files changed, 23 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/arrow/blob/2a2b1094/cpp/src/arrow/io/file.cc
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/io/file.cc b/cpp/src/arrow/io/file.cc
index c4c797c..b2b8801 100644
--- a/cpp/src/arrow/io/file.cc
+++ b/cpp/src/arrow/io/file.cc
@@ -117,6 +117,10 @@ namespace io {
 
 // ----------------------------------------------------------------------
 // Cross-platform file compatability layer
+#if defined(_MSC_VER)
+constexpr const char* kRangeExceptionError =
+    "Range exception during wide-char string conversion";
+#endif
 
 static inline Status CheckOpenResult(
     int ret, int errno_actual, const char* filename, size_t filename_length) {
@@ -131,8 +135,10 @@ static inline Status CheckOpenResult(
     std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> converter;
     std::wstring wide_string(
         reinterpret_cast<const wchar_t*>(filename), filename_length / sizeof(wchar_t));
-    std::string byte_string = converter.to_bytes(wide_string);
-    ss << byte_string;
+    try {
+      std::string byte_string = converter.to_bytes(wide_string);
+      ss << byte_string;
+    } catch (const std::range_error&) { ss << kRangeExceptionError; }
 #else
     ss << filename;
 #endif
@@ -162,7 +168,9 @@ static inline Status ConvertToUtf16(const std::string& input, std::wstring*
resu
   }
 
   std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> utf16_converter;
-  *result = utf16_converter.from_bytes(input);
+  try {
+    *result = utf16_converter.from_bytes(input);
+  } catch (const std::range_error&) { return Status::Invalid(kRangeExceptionError); }
   return Status::OK();
 }
 #endif

http://git-wip-us.apache.org/repos/asf/arrow/blob/2a2b1094/cpp/src/arrow/io/io-file-test.cc
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/io/io-file-test.cc b/cpp/src/arrow/io/io-file-test.cc
index 3450bae..1b7e052 100644
--- a/cpp/src/arrow/io/io-file-test.cc
+++ b/cpp/src/arrow/io/io-file-test.cc
@@ -96,6 +96,18 @@ class TestFileOutputStream : public FileTestFixture {
   std::shared_ptr<FileOutputStream> file_;
 };
 
+#if defined(_MSC_VER)
+TEST_F(TestFileOutputStream, FileNameWideCharConversionRangeException) {
+  std::shared_ptr<FileOutputStream> file;
+  // Form literal string with non-ASCII symbol(127 + 1)
+  std::string file_name = "\x80";
+  ASSERT_RAISES(Invalid, FileOutputStream::Open(file_name, &file));
+
+  std::shared_ptr<ReadableFile> rd_file;
+  ASSERT_RAISES(Invalid, ReadableFile::Open(file_name, &rd_file));
+}
+#endif
+
 TEST_F(TestFileOutputStream, DestructorClosesFile) {
   int fd;
   {


Mime
View raw message