Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] bug42541 - Anonymous Structures cause NPE in full parse

Fixed NPE in CompleParseASTFactory.createClassSpecifier caused by a null 
name.


-Andrew

Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.tests/ChangeLog,v
retrieving revision 1.76
diff -u -r1.76 ChangeLog
--- ChangeLog	4 Sep 2003 14:39:07 -0000	1.76
+++ ChangeLog	4 Sep 2003 15:37:46 -0000
@@ -1,3 +1,6 @@
+2003-09-04 Andrew Niefer
+	Added testBug42541 to CompleParseASTTests.java
+
 2003-09-04 Hoda Amer
 	Call to ASTExpression getTypeId() changed to getTypeIdString().
 	
Index: parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java,v
retrieving revision 1.19
diff -u -r1.19 CompleteParseASTTest.java
--- parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java	3 Sep 2003 15:16:03 -0000	1.19
+++ parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java	4 Sep 2003 15:37:46 -0000
@@ -567,4 +567,15 @@
 		IASTClassSpecifier classB = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)sub.next()).getTypeSpecifier();
 		IASTClassSpecifier structA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)( getDeclarations( classB ).next())).getTypeSpecifier();
 	}
+	
+	public void testBug42541() throws Exception
+	{
+		Iterator i = parse( "union{ int v; char a; } id;" ).getDeclarations();
+		IASTVariable id = (IASTVariable)i.next();
+		
+		IASTClassSpecifier union = (IASTClassSpecifier) id.getAbstractDeclaration().getTypeSpecifier();
+		Iterator sub = getDeclarations( union );
+		IASTField intV  = (IASTField)sub.next();
+		IASTField charA = (IASTField)sub.next();
+	}
 }
Index: parser/ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/ChangeLog,v
retrieving revision 1.109
diff -u -r1.109 ChangeLog
--- parser/ChangeLog	3 Sep 2003 20:57:44 -0000	1.109
+++ parser/ChangeLog	4 Sep 2003 15:38:41 -0000
@@ -1,3 +1,6 @@
+2003-09-04 Andrew Niefer
+	Fix bug42541 - Anonymous structures cause NPE in full parse
+
 2003-09-03 Andrew Niefer
 	fix bug in PST that prevents > 2 constructors
 
Index: parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java,v
retrieving revision 1.25
diff -u -r1.25 CompleteParseASTFactory.java
--- parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java	4 Sep 2003 14:39:15 -0000	1.25
+++ parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java	4 Sep 2003 15:38:42 -0000
@@ -431,35 +431,42 @@
         IContainerSymbol currentScopeSymbol = scopeToSymbol(scope);
         TypeInfo.eType pstType = classKindToTypeInfo(kind);		
 		List references = new ArrayList();
-		IToken lastToken = name.getLastToken();
-		if( name.length() != 1 ) // qualified name 
-		{
-			 ITokenDuple containerSymbolName = 
-			 	name.getSubrange( 0, name.length() - 3 ); // -1 for index, -2 for last hop of qualified name
-			 currentScopeSymbol = (IContainerSymbol)lookupQualifiedName( currentScopeSymbol, 
-			 	containerSymbolName, references, true);
-			 if( currentScopeSymbol == null )
-			 	throw new ASTSemanticException();
+
+		String newSymbolName = "";
+		
+		if( name != null ){
+			IToken lastToken = name.getLastToken();
+			if( name.length() != 1 ) // qualified name 
+			{
+				 ITokenDuple containerSymbolName = 
+					name.getSubrange( 0, name.length() - 3 ); // -1 for index, -2 for last hop of qualified name
+				 currentScopeSymbol = (IContainerSymbol)lookupQualifiedName( currentScopeSymbol, 
+					containerSymbolName, references, true);
+				 if( currentScopeSymbol == null )
+					throw new ASTSemanticException();
+			}
+			newSymbolName = lastToken.getImage();
 		}
 		
 		ISymbol classSymbol = null;
-        try
-        {
-            classSymbol = currentScopeSymbol.lookupMemberForDefinition(lastToken.getImage());
-        }
-        catch (ParserSymbolTableException e)
-        {
-            throw new ASTSemanticException();
-        }
-        
-        if( classSymbol != null && ! classSymbol.isForwardDeclaration() )
-			throw new ASTSemanticException();
-		
-		if( classSymbol != null && classSymbol.getType() != pstType )
-			throw new ASTSemanticException();
-
+		if( !newSymbolName.equals("") ){
+			try
+			{
+				classSymbol = currentScopeSymbol.lookupMemberForDefinition(newSymbolName);
+			}
+			catch (ParserSymbolTableException e)
+			{
+				throw new ASTSemanticException();
+			}
+	        
+			if( classSymbol != null && ! classSymbol.isForwardDeclaration() )
+				throw new ASTSemanticException();
+			
+			if( classSymbol != null && classSymbol.getType() != pstType )
+				throw new ASTSemanticException();
+		}
 
-		IDerivableContainerSymbol newSymbol = pst.newDerivableContainerSymbol( lastToken.getImage(), pstType );
+		IDerivableContainerSymbol newSymbol = pst.newDerivableContainerSymbol( newSymbolName, pstType );
 		
 		if( classSymbol != null )
 			classSymbol.setTypeSymbol( newSymbol );

Back to the top