Btrfs: don't access non-existent key when csum tree is empty
[cascardo/linux.git] / fs / btrfs / file-item.c
index 67751b7..609d56b 100644 (file)
@@ -750,7 +750,7 @@ again:
                int slot = path->slots[0] + 1;
                /* we didn't find a csum item, insert one */
                nritems = btrfs_header_nritems(path->nodes[0]);
-               if (path->slots[0] >= nritems - 1) {
+               if (!nritems || (path->slots[0] >= nritems - 1)) {
                        ret = btrfs_next_leaf(root, path);
                        if (ret == 1)
                                found_next = 1;