am a06c9707: Merge "Add sanity checks to fix crash" into klp-dev

* commit 'a06c97077c838df13a3882d57e841d584fa4aebc':
  Add sanity checks to fix crash
diff --git a/Tremolo/codebook.c b/Tremolo/codebook.c
index 0ff3529..66979dc 100644
--- a/Tremolo/codebook.c
+++ b/Tremolo/codebook.c
@@ -210,6 +210,20 @@
     }
   }
 
+  // following sanity check copied from libvorbis
+  /* sanity check the huffman tree; an underpopulated tree must be
+     rejected. The only exception is the one-node pseudo-nil tree,
+     which appears to be underpopulated because the tree doesn't
+     really exist; there's only one possible 'codeword' or zero bits,
+     but the above tree-gen code doesn't mark that. */
+  if(b->used_entries != 1){
+    for(i=1;i<33;i++)
+      if(marker[i] & (0xffffffffUL>>(32-i))){
+          return 1;
+      }
+  }
+
+
   return 0;
 }