compiler/libec: Fixed null pointer compiler crashes
authorJerome St-Louis <jerome@ecere.com>
Wed, 6 Aug 2014 21:41:23 +0000 (17:41 -0400)
committerJerome St-Louis <jerome@ecere.com>
Wed, 6 Aug 2014 21:41:23 +0000 (17:41 -0400)
compiler/bootstrap/libec/bootstrap/loadSymbols.c
compiler/bootstrap/libec/bootstrap/pass15.c
compiler/bootstrap/libec/bootstrap/pass16.c
compiler/libec/src/loadSymbols.ec
compiler/libec/src/pass15.ec
compiler/libec/src/pass16.ec

index 7094cdb..ad9e318 100644 (file)
@@ -1173,9 +1173,12 @@ else if(regClass && regClass->type == 2)
 {
 struct __ecereNameSpace__ecere__com__BitMember * member = __ecereNameSpace__ecere__com__eClass_AddBitMember(regClass, name, line[0] ? line : 0, 0, 0, memberAccess);
 
+if(member)
+{
 member->size = size;
 member->pos = bitPos;
 }
+}
 else if(regClass)
 {
 if(!__ecereNameSpace__ecere__com__eClass_AddDataMember(regClass, name, line[0] ? line : 0, 0, 0, memberAccess))
index be8261f..1084768 100644 (file)
@@ -7579,7 +7579,7 @@ struct Type * type = exp->expType;
 
 if(type)
 {
-while(type->kind == 8 && type->__anon1._class->__anon1.registered && (type->__anon1._class->__anon1.registered->type == 2 || type->__anon1._class->__anon1.registered->type == 3 || type->__anon1._class->__anon1.registered->type == 4))
+while(type->kind == 8 && type->__anon1._class && type->__anon1._class->__anon1.registered && (type->__anon1._class->__anon1.registered->type == 2 || type->__anon1._class->__anon1.registered->type == 3 || type->__anon1._class->__anon1.registered->type == 4))
 {
 if(!type->__anon1._class->__anon1.registered->dataType)
 type->__anon1._class->__anon1.registered->dataType = ProcessTypeString(type->__anon1._class->__anon1.registered->dataTypeString, 0);
@@ -9886,6 +9886,8 @@ if(!id->_class || !id->_class->__anon1.__anon1.name || strcmp(id->_class->__anon
 {
 for(ctx = curContext; ctx != topContext->parent && !symbol; ctx = ctx->parent)
 {
+if(!ctx)
+break;
 symbol = (struct Symbol *)__ecereMethod___ecereNameSpace__ecere__sys__BinaryTree_FindString(&ctx->symbols, id->string);
 if(symbol)
 break;
index 7143465..33b066d 100644 (file)
@@ -1819,7 +1819,7 @@ for(member = (*members->__anon1.dataMembers).first; member; member = member->nex
 struct Identifier * ident = (((void *)0));
 struct __ecereNameSpace__ecere__com__DataMember * thisMember = (((void *)0));
 
-if(member->identifiers)
+if(member->identifiers && (*member->identifiers).first)
 {
 struct __ecereNameSpace__ecere__com__DataMember * _subMemberStack[256];
 int _subMemberStackPos = 0;
@@ -3000,9 +3000,12 @@ struct Declaration * dummyDecl;
 
 {
 dummyDecl = MkDeclaration((((void *)0)), (((void *)0)));
+if(curCompound)
+{
 if(!curCompound->__anon1.compound.declarations)
 curCompound->__anon1.compound.declarations = MkList();
 __ecereMethod___ecereNameSpace__ecere__sys__OldList_Insert((&*curCompound->__anon1.compound.declarations), (((void *)0)), dummyDecl);
+}
 sprintf(className, "__simpleStruct%d", curContext->simpleID++);
 {
 struct __ecereNameSpace__ecere__sys__OldList * list = MkList();
index dbda622..c75b756 100644 (file)
@@ -90,8 +90,11 @@ static void ReadDataMembers(Class regClass, DataMember member, File f)
             {
                //eClass_AddBitMember(regClass, name, line[0] ? line : 0, size, bitPos);
                BitMember member = eClass_AddBitMember(regClass, name, line[0] ? line : 0, 0, 0, memberAccess);
-               member.size = size;
-               member.pos = bitPos;
+               if(member)
+               {
+                  member.size = size;
+                  member.pos = bitPos;
+               }
             }
             else if(regClass)
             {
index b39a9bb..50bc46f 100644 (file)
@@ -121,6 +121,7 @@ static void ReplaceClassMembers(Expression exp, Class _class)
          // First, check if the identifier is declared inside the function
          for(ctx = curContext; ctx != topContext.parent && !symbol; ctx = ctx.parent)
          {
+            if(!ctx) break;   // This happened opening old mapTileCache.ec from archives?
             symbol = (Symbol)ctx.symbols.FindString(id.string);
             if(symbol) break;
          }
@@ -4389,7 +4390,7 @@ public Operand GetOperand(Expression exp)
    Type type = exp.expType;
    if(type)
    {
-      while(type.kind == classType &&
+      while(type.kind == classType && type._class &&
          type._class.registered && (type._class.registered.type == bitClass || type._class.registered.type == unitClass || type._class.registered.type == enumClass))
       {
          if(!type._class.registered.dataType)
index 5922ddd..b5fcf89 100644 (file)
@@ -583,7 +583,7 @@ static bool ProcessInstMembers(Instantiation inst, Expression instExp, OldList l
                {
                   Identifier ident = null;
                   DataMember thisMember = null;
-                  if(member.identifiers)
+                  if(member.identifiers && member.identifiers->first)
                   {
                      DataMember _subMemberStack[256];
                      int _subMemberStackPos = 0;
@@ -938,9 +938,12 @@ static void ProcessExpression(Expression exp)
 
                      // TRICKY STUFF, UGLY HACK FOR stateSizeAnchor = SizeAnchor { size.w = 10 };
                      dummyDecl = MkDeclaration(null,null);
-                     if(!curCompound.compound.declarations)
-                        curCompound.compound.declarations = MkList();
-                     curCompound.compound.declarations->Insert(null, dummyDecl);
+                     if(curCompound)
+                     {
+                        if(!curCompound.compound.declarations)
+                           curCompound.compound.declarations = MkList();
+                        curCompound.compound.declarations->Insert(null, dummyDecl);
+                     }
 
                      sprintf(className, "__simpleStruct%d", curContext.simpleID++);