From 5e0f46583b313efe53f66d7c236f871dc7cb0a53 Mon Sep 17 00:00:00 2001 From: Silvio Date: Fri, 26 Jul 2024 11:00:05 +0200 Subject: [PATCH 1/2] Fix sending empty yarp::sig::Vector in Debug build type --- src/libYARP_sig/src/yarp/sig/Vector.cpp | 12 +++++--- src/libYARP_sig/tests/VectorOfTest.cpp | 37 ++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/src/libYARP_sig/src/yarp/sig/Vector.cpp b/src/libYARP_sig/src/yarp/sig/Vector.cpp index 2e190931e7f..6add16bc639 100644 --- a/src/libYARP_sig/src/yarp/sig/Vector.cpp +++ b/src/libYARP_sig/src/yarp/sig/Vector.cpp @@ -84,11 +84,15 @@ bool VectorBase::write(yarp::os::ConnectionWriter& connection) const { header.listLen = (int)getListSize(); connection.appendBlock((char*)&header, sizeof(header)); - const char *ptr = getMemoryBlock(); - int elemSize=getElementSize(); - yCAssert(VECTOR, ptr != nullptr); - connection.appendExternalBlock(ptr, elemSize*header.listLen); + if (header.listLen > 0) + { + const char *ptr = getMemoryBlock(); + int elemSize=getElementSize(); + yCAssert(VECTOR, ptr != nullptr); + + connection.appendExternalBlock(ptr, elemSize*header.listLen); + } // if someone is foolish enough to connect in text mode, // let them see something readable. diff --git a/src/libYARP_sig/tests/VectorOfTest.cpp b/src/libYARP_sig/tests/VectorOfTest.cpp index 35f30a484ad..643c7d7ca85 100644 --- a/src/libYARP_sig/tests/VectorOfTest.cpp +++ b/src/libYARP_sig/tests/VectorOfTest.cpp @@ -31,7 +31,6 @@ TEST_CASE("sig::VectorOfTest", "[yarp::sig]") SECTION("Check send and receive integers") { INFO("check VectorO send receive"); - { Port portIn; Port portOut; @@ -79,6 +78,42 @@ TEST_CASE("sig::VectorOfTest", "[yarp::sig]") portIn.close(); } + INFO("check VectorOf send empty vector"); + { + Port portIn; + Port portOut; + + portOut.open("/harness_sig/vtest/empty_vector/o"); + portIn.open("/harness_sig/vtest/empty_vector/i"); + + Network::connect("/harness_sig/vtest/empty_vector/o", "/harness_sig/vtest/empty_vector/i"); + + portOut.enableBackgroundWrite(true); + + + VectorOf vector; + vector.resize(0); + + bool success = true; + portOut.write(vector); + + VectorOf tmp; + portIn.read(tmp); + + //compare vector and tmp + if (tmp.size() != vector.size()) + { + success = false; + } + + CHECK(success); // empty VectorOf was sent and received correctly + + portOut.interrupt(); + portOut.close(); + portIn.interrupt(); + portIn.close(); + } + INFO("check VectorOf bottle compatibility"); { //write the same vector again and receive it as a bottle From 39b4fef6505d225603abd91ef149f245784bbc02 Mon Sep 17 00:00:00 2001 From: Silvio Traversaro Date: Fri, 26 Jul 2024 11:39:03 +0200 Subject: [PATCH 2/2] Update release notes --- doc/release/master.md | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/release/master.md b/doc/release/master.md index a2a4e6d3661..4eb546ff369 100644 --- a/doc/release/master.md +++ b/doc/release/master.md @@ -32,6 +32,7 @@ Fixes * `yarpbatterygui` now compatible with battery_nwc_yarp. * Fixed compilation of portmonitor carrier when a custom non-system swig is used * Fixed compatibility with ffmpeg 7 (https://github.com/robotology/yarp/pull/3109). +* Fix sending empty yarp::sig::Vector when building in Debug (https://github.com/robotology/yarp/pull/3123). New Features ------------