diff --git a/modules/taxonomy/taxonomy.module b/modules/taxonomy/taxonomy.module
index 45f8f58a3a9cccec5fd66a781bb341ebf1095707..3fc560c22facff541b2a1d9bdb367103077c6d80 100644
--- a/modules/taxonomy/taxonomy.module
+++ b/modules/taxonomy/taxonomy.module
@@ -788,7 +788,7 @@ function taxonomy_term_count_nodes($tid, $type = 0) {
   foreach (_taxonomy_term_children($tid) as $c) {
     $children_count += taxonomy_term_count_nodes($c, $type);
   }
-  return $count[$type][$tid] + $children_count;
+  return $children_count + (isset($count[$type][$tid]) ? $count[$type][$tid] : 0);
 }
 
 /**