File tree Expand file tree Collapse file tree 3 files changed +10
-3
lines changed Expand file tree Collapse file tree 3 files changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -45,6 +45,13 @@ class CppParser
4545
4646public:
4747 std::unique_ptr<cppast::CppCompound> parseFile (const std::string& filename);
48+ /* *
49+ * @brief Parses the given stream and returns the AST.
50+ * @param stm The stream to parse.
51+ * @param stmSize The size of the stream.
52+ * @return The AST.
53+ * @warning The stream \a stm must terminate with double null characters, i.e. the last 2 bytes must be '\0'.
54+ */
4855 std::unique_ptr<cppast::CppCompound> parseStream (char * stm, size_t stmSize);
4956
5057 void setErrorHandler (ErrorHandler errorHandler);
Original file line number Diff line number Diff line change @@ -111,8 +111,8 @@ std::unique_ptr<cppast::CppCompound> CppParser::parseFile(const std::string& fil
111111
112112std::unique_ptr<cppast::CppCompound> CppParser::parseStream (char * stm, size_t stmSize)
113113{
114- if (stm == nullptr || stmSize == 0 )
115- return nullptr ;
114+ if (( stm == nullptr ) || ( stmSize < 2 ) || (stm[stmSize - 1 ] != ' \0 ' ) || (stm[stmSize - 2 ] != ' \0 ' ) )
115+ throw std::invalid_argument ( " Stream must be valid and it must terminate with double null characters " ) ;
116116 return ::parseStream (stm, stmSize);
117117}
118118
Original file line number Diff line number Diff line change @@ -59,7 +59,7 @@ class EmbeddedSnippetTestBase
5959 */
6060 std::string getTestSnippetParseStream (int lastSnippetBeforeLineNum) const
6161 {
62- return getTestSnippet (lastSnippetBeforeLineNum).append (3 , ' \0 ' );
62+ return getTestSnippet (lastSnippetBeforeLineNum).append (2 , ' \0 ' );
6363 }
6464};
6565
You can’t perform that action at this time.
0 commit comments