]> git.apps.os.sepia.ceph.com Git - xfstests-dev.git/commitdiff
idmapped-mounts: Fix build error because of undefined reallocarray
authorYang Xu <xuyang2018.jy@fujitsu.com>
Wed, 1 Sep 2021 12:43:26 +0000 (20:43 +0800)
committerEryu Guan <guaneryu@gmail.com>
Sun, 5 Sep 2021 14:06:41 +0000 (22:06 +0800)
On old glibc, reallocarray was not introduced, so this case compiles
failed.  We should use reallocarray if glibc supports and use
realloc if glibcs doesn't support reallocarray.

Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
Reviewed-by: Eryu Guan <guaneryu@gmail.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
configure.ac
src/idmapped-mounts/idmapped-mounts.c

index 0b55455a8daf3b6c7e42a706c291727a4854190d..6e5ab397301e3cd6a29bfcffe25e371942a91b3d 100644 (file)
@@ -68,6 +68,7 @@ AC_PACKAGE_WANT_LIBBTRFSUTIL
 
 AC_HAVE_COPY_FILE_RANGE
 AC_CHECK_FUNCS([renameat2])
+AC_CHECK_FUNCS([reallocarray])
 AC_CHECK_TYPES([struct mount_attr], [], [], [[#include <linux/mount.h>]])
 AC_CHECK_TYPES([struct btrfs_qgroup_limit], [], [], [[
 #include <stddef.h>
index 4230cb48c7bf6b081376bee8db13eff258c2ac2e..83b7c89ab01571ae8609c5605539d0992ab996e6 100644 (file)
@@ -9910,8 +9910,12 @@ static int append_stack(struct btrfs_iter *iter, uint64_t tree_id, size_t path_l
        if (iter->stack_len >= iter->stack_capacity) {
                size_t new_capacity = iter->stack_capacity * 2;
                struct btrfs_stack *new_search_stack;
+#ifdef HAVE_REALLOCARRAY
                new_search_stack = reallocarray(iter->search_stack, new_capacity,
                                                sizeof(*iter->search_stack));
+#else
+               new_search_stack = realloc(iter->search_stack, new_capacity * sizeof(*iter->search_stack));
+#endif
                if (!new_search_stack)
                        return -ENOMEM;