[Mesa-dev] [PATCH 09/10] mesa: add null checks for callocs in symbol_table.c

Juha-Pekka Heikkila juhapekka.heikkila at gmail.com
Mon Feb 17 08:21:32 PST 2014


Signed-off-by: Juha-Pekka Heikkila <juhapekka.heikkila at gmail.com>
---
 src/mesa/program/symbol_table.c | 26 +++++++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)

diff --git a/src/mesa/program/symbol_table.c b/src/mesa/program/symbol_table.c
index 64e24d8..df1ec5c 100644
--- a/src/mesa/program/symbol_table.c
+++ b/src/mesa/program/symbol_table.c
@@ -188,9 +188,11 @@ _mesa_symbol_table_push_scope(struct _mesa_symbol_table *table)
 {
     struct scope_level *const scope = calloc(1, sizeof(*scope));
     
-    scope->next = table->current_scope;
-    table->current_scope = scope;
-    table->depth++;
+    if (scope) {
+        scope->next = table->current_scope;
+        table->current_scope = scope;
+        table->depth++;
+    }
 }
 
 
@@ -338,6 +340,11 @@ _mesa_symbol_table_add_symbol(struct _mesa_symbol_table *table,
 
     if (hdr == NULL) {
        hdr = calloc(1, sizeof(*hdr));
+
+       if (hdr == NULL) {
+           return -1;
+       }
+
        hdr->name = strdup(name);
 
        hash_table_insert(table->ht, hdr, hdr->name);
@@ -360,6 +367,11 @@ _mesa_symbol_table_add_symbol(struct _mesa_symbol_table *table,
        return -1;
 
     sym = calloc(1, sizeof(*sym));
+
+    if (sym == NULL) {
+        return -1;
+    }
+
     sym->next_with_same_name = hdr->symbols;
     sym->next_with_same_scope = table->current_scope->symbols;
     sym->hdr = hdr;
@@ -395,6 +407,10 @@ _mesa_symbol_table_add_global_symbol(struct _mesa_symbol_table *table,
 
     if (hdr == NULL) {
         hdr = calloc(1, sizeof(*hdr));
+        if (hdr == NULL) {
+            return -1;
+        }
+
         hdr->name = strdup(name);
 
         hash_table_insert(table->ht, hdr, hdr->name);
@@ -424,6 +440,10 @@ _mesa_symbol_table_add_global_symbol(struct _mesa_symbol_table *table,
     }
 
     sym = calloc(1, sizeof(*sym));
+    if (sym == NULL) {
+        return -1;
+    }
+
     sym->next_with_same_scope = top_scope->symbols;
     sym->hdr = hdr;
     sym->name_space = name_space;
-- 
1.8.1.2



More information about the mesa-dev mailing list