diff --git a/source/Lib/CommonLib/CommonDef.h b/source/Lib/CommonLib/CommonDef.h
index d46f0610e2f2cdb783bb9724821e53217b145785..e8f1faf1daf39b3db46e5028d6ff8003c706a69b 100644
--- a/source/Lib/CommonLib/CommonDef.h
+++ b/source/Lib/CommonLib/CommonDef.h
@@ -685,6 +685,7 @@ static inline int floorLog2(uint32_t x)
 {
   if (x == 0)
   {
+    // note: ceilLog2() expects -1 as return value
     return -1;
   }
 #ifdef __GNUC__
@@ -728,7 +729,7 @@ static inline int floorLog2(uint32_t x)
 
 static inline int ceilLog2(uint32_t x)
 {
-  return floorLog2(x - 1) + 1;
+  return (x==0) ? -1 : floorLog2(x - 1);
 }