erofs-utils: more sanity check for buffer allocation optimization

In case that new buffer allocation optimization logic is
potentially broken.

Link: https://lore.kernel.org/r/20210214153549.2454-2-hsiangkao@aol.com
Reviewed-by: Li Guifu <bluce.lee@aliyun.com>
Signed-off-by: Gao Xiang <hsiangkao@aol.com>
diff --git a/lib/cache.c b/lib/cache.c
index 6ae2b20..340dcdd 100644
--- a/lib/cache.c
+++ b/lib/cache.c
@@ -186,8 +186,14 @@
 				       mapped_list);
 
 		/* last mapped block can be expended, don't handle it here */
-		if (cur == last_mapped_block)
+		if (list_next_entry(cur, list)->blkaddr == NULL_ADDR) {
+			DBG_BUGON(cur != last_mapped_block);
 			continue;
+		}
+
+		DBG_BUGON(cur->type != type);
+		DBG_BUGON(cur->blkaddr == NULL_ADDR);
+		DBG_BUGON(used_before != cur->buffers.off % EROFS_BLKSIZ);
 
 		ret = __erofs_battach(cur, NULL, size, alignsize,
 				      required_ext + inline_ext, true);