This is an automated email from the ASF dual-hosted git repository.

jmalkin pushed a commit to branch vo_exception_safety
in repository https://gitbox.apache.org/repos/asf/incubator-datasketches-cpp.git


The following commit(s) were added to refs/heads/vo_exception_safety by this 
push:
     new 8403e16  fix index bug in serde cleaning up strings, update varopt 
tests to work with gcc 4.8
8403e16 is described below

commit 8403e163f4b20ac3854f31a7c7a6ce993ba56a45
Author: Jon Malkin <[email protected]>
AuthorDate: Fri May 8 14:35:42 2020 -0700

    fix index bug in serde cleaning up strings, update varopt tests to work 
with gcc 4.8
---
 common/include/serde.hpp              |  2 +-
 sampling/test/var_opt_sketch_test.cpp | 27 ++++++++++++---------------
 sampling/test/var_opt_union_test.cpp  | 12 +++---------
 3 files changed, 16 insertions(+), 25 deletions(-)

diff --git a/common/include/serde.hpp b/common/include/serde.hpp
index fb9aebf..cbd98f2 100644
--- a/common/include/serde.hpp
+++ b/common/include/serde.hpp
@@ -133,7 +133,7 @@ struct serde<std::string> {
     if (failure || !is.good()) {
       // clean up what we've already allocated
       for (unsigned j = 0; j < i; ++j) {
-        items[i].~basic_string();
+        items[j].~basic_string();
       }
       throw std::runtime_error("error reading from std::istream at item " + 
std::to_string(i)); 
     }
diff --git a/sampling/test/var_opt_sketch_test.cpp 
b/sampling/test/var_opt_sketch_test.cpp
index 8c5e15a..384a0ed 100644
--- a/sampling/test/var_opt_sketch_test.cpp
+++ b/sampling/test/var_opt_sketch_test.cpp
@@ -69,13 +69,6 @@ static void check_if_equal(var_opt_sketch<T,S,A>& sk1, 
var_opt_sketch<T,S,A>& sk
   REQUIRE((it1 == sk1.end() && it2 == sk2.end())); // iterators must end at 
the same time
 }
 
-static std::stringstream create_stringstream_with_length(std::vector<uint8_t> 
bytes, size_t length) {
-  std::stringstream ss(std::ios::in | std::ios::out | std::ios::binary);
-  std::string str((char*)&bytes[0], length);
-  ss.str(str);
-  return ss;
-}
-
 TEST_CASE("varopt sketch: invalid k", "[var_opt_sketch]") {
   REQUIRE_THROWS_AS(var_opt_sketch<int>(0), std::invalid_argument);
   REQUIRE_THROWS_AS(var_opt_sketch<int>(1 << 31), std::invalid_argument); // 
aka k < 0
@@ -249,8 +242,9 @@ TEST_CASE("varopt sketch: under-full sketch serialization", 
"[var_opt_sketch]")
 
   // ensure we unroll properly
   REQUIRE_THROWS_AS(var_opt_sketch<int>::deserialize(bytes.data(), 
bytes.size() - 1), std::out_of_range);
-  std::stringstream ss_trunc = create_stringstream_with_length(bytes, 
bytes.size() - 1);
-  REQUIRE_THROWS_AS(var_opt_sketch<int>::deserialize(ss_trunc), 
std::runtime_error);
+  std::string str_trunc((char*)&bytes[0], bytes.size() - 1);
+  ss.str(str_trunc);
+  REQUIRE_THROWS_AS(var_opt_sketch<int>::deserialize(ss), std::runtime_error);
 }
 
 TEST_CASE("varopt sketch: end-of-warmup sketch serialization", 
"[var_opt_sketch]") {
@@ -270,8 +264,9 @@ TEST_CASE("varopt sketch: end-of-warmup sketch 
serialization", "[var_opt_sketch]
 
   // ensure we unroll properly
   REQUIRE_THROWS_AS(var_opt_sketch<int>::deserialize(bytes.data(), 
bytes.size() - 1000), std::out_of_range);
-  std::stringstream ss_trunc = create_stringstream_with_length(bytes, 
bytes.size() - 1000);
-  REQUIRE_THROWS_AS(var_opt_sketch<int>::deserialize(ss_trunc), 
std::runtime_error);
+  std::string str_trunc((char*)&bytes[0], bytes.size() - 100);
+  ss.str(str_trunc);
+  REQUIRE_THROWS_AS(var_opt_sketch<int>::deserialize(ss), std::runtime_error);
 }
 
 TEST_CASE("varopt sketch: full sketch serialization", "[var_opt_sketch]") {
@@ -303,8 +298,9 @@ TEST_CASE("varopt sketch: full sketch serialization", 
"[var_opt_sketch]") {
 
   // ensure we unroll properly
   REQUIRE_THROWS_AS(var_opt_sketch<int>::deserialize(bytes.data(), 
bytes.size() - 100), std::out_of_range);
-  std::stringstream ss_trunc = create_stringstream_with_length(bytes, 
bytes.size() - 100);
-  REQUIRE_THROWS_AS(var_opt_sketch<int>::deserialize(ss_trunc), 
std::runtime_error);
+  std::string str_trunc((char*)&bytes[0], bytes.size() - 100);
+  ss.str(str_trunc);
+  REQUIRE_THROWS_AS(var_opt_sketch<int>::deserialize(ss), std::runtime_error);
 }
 
 TEST_CASE("varopt sketch: string serialization", "[var_opt_sketch]") {
@@ -327,8 +323,9 @@ TEST_CASE("varopt sketch: string serialization", 
"[var_opt_sketch]") {
 
   // ensure we unroll properly
   REQUIRE_THROWS_AS(var_opt_sketch<std::string>::deserialize(bytes.data(), 
bytes.size() - 12), std::out_of_range);
-  std::stringstream ss_trunc = create_stringstream_with_length(bytes, 
bytes.size() - 12);
-  REQUIRE_THROWS_AS(var_opt_sketch<std::string>::deserialize(ss_trunc), 
std::runtime_error);
+  std::string str_trunc((char*)&bytes[0], bytes.size() - 12);
+  ss.str(str_trunc);
+  REQUIRE_THROWS_AS(var_opt_sketch<std::string>::deserialize(ss), 
std::runtime_error);
 }
 
 TEST_CASE("varopt sketch: pseudo-light update", "[var_opt_sketch]") {
diff --git a/sampling/test/var_opt_union_test.cpp 
b/sampling/test/var_opt_union_test.cpp
index e2321c5..d1e6805 100644
--- a/sampling/test/var_opt_union_test.cpp
+++ b/sampling/test/var_opt_union_test.cpp
@@ -54,13 +54,6 @@ static void check_if_equal(var_opt_sketch<T,S,A>& sk1, 
var_opt_sketch<T,S,A>& sk
   REQUIRE((it1 == sk1.end() && it2 == sk2.end())); // iterators must end at 
the same time
 }
 
-static std::stringstream create_stringstream_with_length(std::vector<uint8_t> 
bytes, size_t length) {
-  std::stringstream ss(std::ios::in | std::ios::out | std::ios::binary);
-  std::string str((char*)&bytes[0], length);
-  ss.str(str);
-  return ss;
-}
-
 // compare serialization and deserialization results, checking string and 
stream methods to
 // ensure that the resulting binary images are compatible.
 // if exact_compare = false, checks for equivalence -- specific R region 
values may differ but
@@ -95,9 +88,10 @@ static void 
compare_serialization_deserialization(var_opt_union<T,S,A>& vo_union
 
   // check truncated input, too
   REQUIRE_THROWS_AS(var_opt_union<T>::deserialize(bytes.data(), bytes.size() - 
5), std::out_of_range);
-  std::stringstream ss_trunc = create_stringstream_with_length(bytes, 
bytes.size() - 5);
+  std::string str_trunc((char*)&bytes[0], bytes.size() - 5);
+  ss.str(str_trunc);
   // next line may throw either std::illegal_argument or std::runtime_exception
-  REQUIRE_THROWS_AS(var_opt_union<T>::deserialize(ss_trunc), std::exception);
+  REQUIRE_THROWS_AS(var_opt_union<T>::deserialize(ss), std::exception);
 }
 
 TEST_CASE("varopt union: bad prelongs", "[var_opt_union]") {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to