From 320cc3c60b575fa49e49a21619472f01b8890049 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Tue, 29 Sep 2020 13:27:27 -0700 Subject: [PATCH] shared_vector_convert<>() fix convert of empty array Empty arrays can be untyped, but this doesn't matter. --- src/misc/pv/sharedVector.h | 6 +++++- testApp/misc/testSharedVector.cpp | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/misc/pv/sharedVector.h b/src/misc/pv/sharedVector.h index fa426a7..28322d3 100644 --- a/src/misc/pv/sharedVector.h +++ b/src/misc/pv/sharedVector.h @@ -837,9 +837,13 @@ namespace detail { typedef typename meta::strip_const::type to_t; ScalarType stype = src.original_type(), dtype = (ScalarType)ScalarTypeID::value; - if(stype==dtype) { + if(src.empty()) { + return shared_vector(); + + } else if(stype==dtype) { // no convert needed return shared_vector(src, detail::_shared_vector_cast_tag()); + } else { // alloc and convert shared_vector ret(src.size()/ScalarTypeFunc::elementSize(stype)); diff --git a/testApp/misc/testSharedVector.cpp b/testApp/misc/testSharedVector.cpp index b0d5416..e2b52ef 100644 --- a/testApp/misc/testSharedVector.cpp +++ b/testApp/misc/testSharedVector.cpp @@ -474,6 +474,9 @@ void testVectorConvert() testOk1(ints.unique()); testOk1(strings.size()==ints.size()); testOk1(strings.at(0)=="42"); + + testDiag("convert empty array"); + testOk1(pvd::shared_vector_convert(pvd::shared_vector()).empty()); } void testWeak() @@ -695,7 +698,7 @@ void testCXX11Init() MAIN(testSharedVector) { - testPlan(191); + testPlan(192); testDiag("Tests for shared_vector"); testDiag("sizeof(shared_vector)=%lu",