summaryrefslogtreecommitdiffstats
path: root/include/ipmid
diff options
context:
space:
mode:
authorVernon Mauery <vernon.mauery@linux.intel.com>2019-07-23 16:49:34 -0700
committerVernon Mauery <vernon.mauery@linux.intel.com>2019-09-16 20:12:11 +0000
commitcaabc36b6a7596c6a6deb774770f4271f50942e9 (patch)
tree57e4494de420a05d423260964d57125e4d36ca63 /include/ipmid
parentcb09aa00e8f25fda20780f0a26a7c35b24c4b59b (diff)
downloadphosphor-host-ipmid-caabc36b6a7596c6a6deb774770f4271f50942e9.tar.gz
phosphor-host-ipmid-caabc36b6a7596c6a6deb774770f4271f50942e9.zip
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>
Diffstat (limited to 'include/ipmid')
-rw-r--r--include/ipmid/message/unpack.hpp13
1 files changed, 8 insertions, 5 deletions
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 @@ struct UnpackSingle
p.bitCount = priorBitCount;
p.unpackError = priorError;
}
- return 0;
+ return ret;
}
else
{
@@ -292,18 +292,21 @@ struct UnpackSingle<std::vector<T>>
{
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;
}
};
OpenPOWER on IntegriCloud