Commits

senex committed 99d7165

Fixed bug 3568629: Crash parsing free function with derefence

Comments (0)

Files changed (3)

CppHeaderParser/CppHeaderParser.py

 
         if '{' in stack:
             info['defined'] = True
-            self._method_body = self.braceDepth
+            self._method_body = self.braceDepth + 1
             trace_print( 'NEW METHOD WITH BODY', self.braceDepth )
         elif stack[-1] == ';':
             info['defined'] = False
                         trace_print( 'END OF STRUCT DEF' )
                         self.curStruct = None
 
-                    if self._method_body and self.braceDepth <= self._method_body:
+                    if self._method_body and (self.braceDepth + 1) <= self._method_body:
                         self._method_body = None; self.stack = []; self.nameStack = []; trace_print( 'FORCE CLEAR METHBODY' )
                 
                 if (tok.type == 'OPEN_PAREN'):
             debug_print( "trace" )
             self.evaluate_enum_stack()
 
-        elif self._method_body and self.braceDepth > self._method_body: trace_print( 'INSIDE METHOD DEF' )
+        elif self._method_body and (self.braceDepth + 1) > self._method_body: trace_print( 'INSIDE METHOD DEF' )
         elif is_method_namestack(self.stack) and not self.curStruct and '(' in self.nameStack:
             debug_print( "trace" )
             if self.braceDepth > 0:

CppHeaderParser/test/TestSampleClass.h

         UINT16 raw[3];
     };
 };
+
+// Bug 3568629
+void termite(void)
+{
+    return ((structA*) (Func())->element);
+}

CppHeaderParser/test/test_CppHeaderParser.py

     def test_second_anonymous_union_name(self):
         return self.assertEqual(self.cppHeader.classes["Beans"]["properties"]["public"][3]["name"], "")
 
+
+# Bug: 3567854 and 3568241
+class termite_TestCase(unittest.TestCase):
+
+    def setUp(self):
+        self.cppHeader = CppHeaderParser.CppHeader("TestSampleClass.h")
+    
+    def test_termite_function(self):
+        self.assertEqual(self.cppHeader.functions[5]["name"], "termite")
+
 if __name__ == '__main__':
     unittest.main()