Skip to content

Commit

Permalink
Merge pull request #3123 from traversaro/fixemptyvectordebug
Browse files Browse the repository at this point in the history
Fix sending empty yarp::sig::Vector when building in Debug
  • Loading branch information
randaz81 authored Aug 5, 2024
2 parents dfe6d31 + 39b4fef commit 2fd8e69
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
1 change: 1 addition & 0 deletions doc/release/master.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
------------
Expand Down
12 changes: 8 additions & 4 deletions src/libYARP_sig/src/yarp/sig/Vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
37 changes: 36 additions & 1 deletion src/libYARP_sig/tests/VectorOfTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ TEST_CASE("sig::VectorOfTest", "[yarp::sig]")
SECTION("Check send and receive integers")
{
INFO("check VectorO<int> send receive");

{
Port portIn;
Port portOut;
Expand Down Expand Up @@ -79,6 +78,42 @@ TEST_CASE("sig::VectorOfTest", "[yarp::sig]")
portIn.close();
}

INFO("check VectorOf<int> 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<int> vector;
vector.resize(0);

bool success = true;
portOut.write(vector);

VectorOf<int> tmp;
portIn.read(tmp);

//compare vector and tmp
if (tmp.size() != vector.size())
{
success = false;
}

CHECK(success); // empty VectorOf<int> was sent and received correctly

portOut.interrupt();
portOut.close();
portIn.interrupt();
portIn.close();
}

INFO("check VectorOf<int> bottle compatibility");
{
//write the same vector again and receive it as a bottle
Expand Down

0 comments on commit 2fd8e69

Please sign in to comment.