Resolve several null pointer accesses, when encountering empty declaration statements.
authorChristoph Mallon <christoph.mallon@gmx.de>
Sat, 29 Nov 2008 15:06:45 +0000 (15:06 +0000)
committerChristoph Mallon <christoph.mallon@gmx.de>
Sat, 29 Nov 2008 15:06:45 +0000 (15:06 +0000)
[r24142]

ast2firm.c
parser.c
walk_statements.c

index 6759445..f89c926 100644 (file)
@@ -4311,12 +4311,15 @@ static void initialize_local_declaration(entity_t *entity)
 
 static void declaration_statement_to_firm(declaration_statement_t *statement)
 {
-       entity_t *entity = statement->declarations_begin;
-       entity_t *end    = statement->declarations_end->base.next;
-       for ( ; entity != end; entity = entity->base.next) {
-               if (!is_declaration(entity))
-                       continue;
-               initialize_local_declaration(entity);
+       entity_t *      entity = statement->declarations_begin;
+       entity_t *const last   = statement->declarations_end;
+       if (entity != NULL) {
+               for ( ;; entity = entity->base.next) {
+                       if (is_declaration(entity))
+                               initialize_local_declaration(entity);
+                       if (entity == last)
+                               break;
+               }
        }
 }
 
@@ -5116,10 +5119,10 @@ static void statement_to_firm(statement_t *statement)
 }
 
 static int count_local_variables(const entity_t *entity,
-                                 const entity_t *const end)
+                                 const entity_t *const last)
 {
        int count = 0;
-       for (; entity != end; entity = entity->base.next) {
+       for (; entity != NULL; entity = entity->base.next) {
                type_t *type;
                bool    address_taken;
 
@@ -5135,6 +5138,9 @@ static int count_local_variables(const entity_t *entity,
 
                if (!address_taken && is_type_scalar(type))
                        ++count;
+
+               if (entity == last)
+                       break;
        }
        return count;
 }
@@ -5147,7 +5153,7 @@ static void count_local_variables_in_stmt(statement_t *stmt, void *const env)
        case STATEMENT_DECLARATION: {
                const declaration_statement_t *const decl_stmt = &stmt->declaration;
                *count += count_local_variables(decl_stmt->declarations_begin,
-                                                                               decl_stmt->declarations_end->base.next);
+                               decl_stmt->declarations_end);
                break;
        }
 
index 8078de8..c550062 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -5779,14 +5779,16 @@ static void check_reachable(statement_t *const stmt)
                        declaration_statement_t const *const decl = &stmt->declaration;
                        entity_t                const *      ent  = decl->declarations_begin;
                        entity_t                const *const last = decl->declarations_end;
-                       for (;; ent = ent->base.next) {
-                               if (ent->kind                 == ENTITY_VARIABLE &&
-                                               ent->variable.initializer != NULL            &&
-                                               !initializer_returns(ent->variable.initializer)) {
-                                       return;
+                       if (ent != NULL) {
+                               for (;; ent = ent->base.next) {
+                                       if (ent->kind                 == ENTITY_VARIABLE &&
+                                                       ent->variable.initializer != NULL            &&
+                                                       !initializer_returns(ent->variable.initializer)) {
+                                               return;
+                                       }
+                                       if (ent == last)
+                                               break;
                                }
-                               if (ent == last)
-                                       break;
                        }
                        next = stmt->base.next;
                        break;
index 9e0c491..8a4cbc1 100644 (file)
@@ -116,11 +116,11 @@ static void walk_initializer(const initializer_t  *initializer,
 }
 
 static void walk_declarations(const entity_t*            entity,
-                              const entity_t*      const end,
+                              const entity_t*      const last,
                               statement_callback   const callback,
                               void                *const env)
 {
-       for (; entity != end; entity = entity->base.next) {
+       for (; entity != NULL; entity = entity->base.next) {
                /* we only look at variables */
                if (entity->kind != ENTITY_VARIABLE)
                        continue;
@@ -130,6 +130,9 @@ static void walk_declarations(const entity_t*            entity,
                if (initializer != NULL) {
                        walk_initializer(initializer, callback, env);
                }
+
+               if (entity == last)
+                       break;
        }
 }
 
@@ -197,8 +200,7 @@ void walk_statements(statement_t *const stmt, statement_callback const callback,
 
                case STATEMENT_DECLARATION:
                        walk_declarations(stmt->declaration.declarations_begin,
-                                         stmt->declaration.declarations_end->base.next,
-                                         callback, env);
+                                       stmt->declaration.declarations_end, callback, env);
                        return;
 
                case STATEMENT_MS_TRY: