--- matrix-5.x-1.2/matrix.module	2007-08-30 17:29:08.000000000 +0200
+++ matrix/matrix.module	2007-09-07 20:15:39.000000000 +0200
@@ -173,26 +173,29 @@ function matrix_widget($op, &$node, $fie
 }
 
 function theme_matrix_table_form($form) {
-  $rows = array();
-  $header = $form['header']['#value'];
+  $output = t('No matrix rows and columns defined yet.');
+  if (!empty($form['matrix'])) {
+    $rows = array();
+    $header = $form['header']['#value'];
   
-  foreach ($form['matrix'] as $row_key => $fields) {
-    if (!empty($form['first_col']['#value'][$row_key])) {
-      $row = array();
-      $row[] = $form['first_col']['#value'][$row_key];
-      foreach ($fields as $col_key => $field) {
-        if ($field['#type'] == 'textfield') {
-          $row[] = drupal_render($form['matrix'][$row_key][$col_key]);
+    foreach ($form['matrix'] as $row_key => $fields) {
+      if (!empty($form['first_col']['#value'][$row_key])) {
+        $row = array();
+        $row[] = $form['first_col']['#value'][$row_key];
+        foreach ($fields as $col_key => $field) {
+          if ($field['#type'] == 'textfield') {
+            $row[] = drupal_render($form['matrix'][$row_key][$col_key]);
+          }
         }
+        $rows[] = $row;
       }
-      $rows[] = $row;
     }
-  }
   
-  drupal_render($form['header']);
-  drupal_render($form['first_col']);
-  $output = drupal_render($form);
-  $output .= theme('table', $header, $rows, array('class' => 'matrix'));
+    drupal_render($form['header']);
+    drupal_render($form['first_col']);
+    $output = drupal_render($form);
+    $output .= theme('table', $header, $rows, array('class' => 'matrix'));
+  }
   return $output;
 }
 
