summaryrefslogtreecommitdiffstats
path: root/include/ipmid/message/unpack.hpp
diff options
context:
space:
mode:
authorVernon Mauery <vernon.mauery@linux.intel.com>2019-05-30 15:20:52 -0700
committerVernon Mauery <vernon.mauery@linux.intel.com>2019-05-30 16:54:57 -0700
commita3dd7661d18aeb47bbad271f40cc23efb5dea8b5 (patch)
tree51f4781ba46fc94651c7eb4488b25ac64dc61bf6 /include/ipmid/message/unpack.hpp
parent33298af179718bf6da82634101578eff39b4a9ae (diff)
downloadphosphor-host-ipmid-a3dd7661d18aeb47bbad271f40cc23efb5dea8b5.tar.gz
phosphor-host-ipmid-a3dd7661d18aeb47bbad271f40cc23efb5dea8b5.zip
unpack static assert on unsupported types
Unsupported types might not cause compile time errors but can result in SIGILL errors at runtime when compiler warnings are ignored. This was found when compiling an intel-ipmi-oem handler that attempted to unpack an enum class type. The code compiles down to an empty function (no return statement or value), which can result in all sorts of undefined behavior. This change forces the unsupported types to emit a static assert and fail to compile. Tested: Created a handler that requests an enum class as an input and saw that the build fails with a static assert. Change-Id: I123da15cb001756f07761cf7a60b799469926a2a Signed-off-by: Vernon Mauery <vernon.mauery@linux.intel.com>
Diffstat (limited to 'include/ipmid/message/unpack.hpp')
-rw-r--r--include/ipmid/message/unpack.hpp37
1 files changed, 20 insertions, 17 deletions
diff --git a/include/ipmid/message/unpack.hpp b/include/ipmid/message/unpack.hpp
index fb2b066..5be92c9 100644
--- a/include/ipmid/message/unpack.hpp
+++ b/include/ipmid/message/unpack.hpp
@@ -99,26 +99,29 @@ struct UnpackSingle
}
return 0;
}
- else
+ else if constexpr (utility::is_tuple<T>::value)
{
- if constexpr (utility::is_tuple<T>::value)
+ bool priorError = p.unpackError;
+ size_t priorIndex = p.rawIndex;
+ // more stuff to unroll if partial bytes are out
+ size_t priorBitCount = p.bitCount;
+ fixed_uint_t<details::bitStreamSize> priorBits = p.bitStream;
+ int ret = p.unpack(t);
+ if (ret != 0)
{
- bool priorError = p.unpackError;
- size_t priorIndex = p.rawIndex;
- // more stuff to unroll if partial bytes are out
- size_t priorBitCount = p.bitCount;
- fixed_uint_t<details::bitStreamSize> priorBits = p.bitStream;
- int ret = p.unpack(t);
- if (ret != 0)
- {
- t = T();
- p.rawIndex = priorIndex;
- p.bitStream = priorBits;
- p.bitCount = priorBitCount;
- p.unpackError = priorError;
- }
- return 0;
+ t = T();
+ p.rawIndex = priorIndex;
+ p.bitStream = priorBits;
+ p.bitCount = priorBitCount;
+ p.unpackError = priorError;
}
+ return 0;
+ }
+ else
+ {
+ static_assert(
+ utility::dependent_false<T>::value,
+ "Attempt to unpack a type that has no IPMI unpack operation");
}
}
};
OpenPOWER on IntegriCloud