diff --git a/tag/locallib.php b/tag/locallib.php
index <HASH>..<HASH> 100644
--- a/tag/locallib.php
+++ b/tag/locallib.php
@@ -31,8 +31,10 @@ function tag_print_cloud($nr_of_tags=150, $return=false) {
     }
 
     $tagkeys = array_keys($tagsincloud);
-    $firsttagkey = $tagkeys[0];
-    $maxcount = $tagsincloud[$firsttagkey]->count;
+    if (!empty($tagkeys)) {
+        $firsttagkey = $tagkeys[0];
+        $maxcount = $tagsincloud[$firsttagkey]->count;
+    }
 
     $etags = array();
MDL-<I> Do not try to access the first key of an empty array in case of no tag exists yet. Merged from <I> stable