bcachefs: Fix a memcpy call
authorKent Overstreet <kent.overstreet@gmail.com>
Mon, 17 May 2021 20:10:06 +0000 (16:10 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:03 +0000 (17:09 -0400)
Not supposed to pass a null ptr to memcpy (even if the size is 0).

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
fs/bcachefs/fsck.c

index fcdcf42..a40459d 100644 (file)
@@ -1161,7 +1161,8 @@ static int add_nlink(struct nlink_table *t, u64 inum, u32 snapshot)
                        return -ENOMEM;
                }
 
-               memcpy(d, t->d, t->size * sizeof(t->d[0]));
+               if (t->d)
+                       memcpy(d, t->d, t->size * sizeof(t->d[0]));
                kvfree(t->d);
 
                t->d = d;