fix logic error for unpack vector of tuple
Unpacking a vector of tuples is failing if the correct number of bytes
does not match an integral number of bytes needed to fully unpack all
the tuples.
Unpacking a tuple should return an error if it does not fully unpack all
the items. This will signal the vector unpack to bail and return however
many items it has unpacked to that point.
A vector unpack should always return success because no matter how many
items it has unpacked, it is fine, because a vector can have any number
of items.
Tested: Unit tests updated to check for proper unpacking of vectors and
tuples (and optionals) as well as new unit tests added for more
targetted testing.
Change-Id: I4b45198f8bc4a49913beb923d10079983179402a
Signed-off-by: Vernon Mauery <vernon.mauery@linux.intel.com>
diff --git a/include/ipmid/message/unpack.hpp b/include/ipmid/message/unpack.hpp
index 5be92c9..d9ccba4 100644
--- a/include/ipmid/message/unpack.hpp
+++ b/include/ipmid/message/unpack.hpp
@@ -115,7 +115,7 @@
p.bitCount = priorBitCount;
p.unpackError = priorError;
}
- return 0;
+ return ret;
}
else
{
@@ -292,18 +292,21 @@
{
static int op(Payload& p, std::vector<T>& t)
{
- int ret = 0;
while (p.rawIndex < p.raw.size())
{
t.emplace_back();
- ret = UnpackSingle<T>::op(p, t.back());
- if (ret)
+ if (UnpackSingle<T>::op(p, t.back()))
{
t.pop_back();
break;
}
}
- return ret;
+ // unpacking a vector is always successful:
+ // either stuff was unpacked successfully (return 0)
+ // or stuff was not unpacked, but should still return
+ // success because an empty vector or a not-fully-unpacked
+ // payload is not a failure.
+ return 0;
}
};