From 5ae48a0380b3377d43f1cb06d6061af796b5fa6d Mon Sep 17 00:00:00 2001 From: thebusytypist Date: Wed, 15 Apr 2015 15:21:42 +0800 Subject: [PATCH] Assert on impossible state transition in Transit(); Put the last case and all non-enumerated cases(also supply assertion for them) in for code coverage. --- include/rapidjson/reader.h | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/include/rapidjson/reader.h b/include/rapidjson/reader.h index a2b6379..e0b9c8c 100644 --- a/include/rapidjson/reader.h +++ b/include/rapidjson/reader.h @@ -1228,13 +1228,6 @@ private: template RAPIDJSON_FORCEINLINE IterativeParsingState Transit(IterativeParsingState src, Token token, IterativeParsingState dst, InputStream& is, Handler& handler) { switch (dst) { - case IterativeParsingStartState: - RAPIDJSON_ASSERT(false); - return IterativeParsingErrorState; - - case IterativeParsingFinishState: - return dst; - case IterativeParsingErrorState: return dst; @@ -1350,17 +1343,25 @@ private: } } - case IterativeParsingValueState: + default: + // This branch is for IterativeParsingValueState actually. + // Use `default:` rather than + // `case IterativeParsingValueState:` is for code coverage. + + // The IterativeParsingStartState is not enumerated in this switch-case. + // It is impossible for that case. And it can be caught by following assertion. + + // The IterativeParsingFinishState is not enumerated in this switch-case either. + // It is a "derivative" state which cannot triggered from Predict() directly. + // Therefore it cannot happen here. And it can be caught by following assertion. + RAPIDJSON_ASSERT(dst == IterativeParsingValueState); + // Must be non-compound value. Or it would be ObjectInitial or ArrayInitial state. ParseValue(is, handler); if (HasParseError()) { return IterativeParsingErrorState; } return IterativeParsingFinishState; - - default: - RAPIDJSON_ASSERT(false); - return IterativeParsingErrorState; } }