From: Yang Xu Date: Wed, 1 Sep 2021 12:43:26 +0000 (+0800) Subject: idmapped-mounts: Fix build error because of undefined reallocarray X-Git-Tag: v2022.05.01~244 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=83f9f983d95a4d5d1736ea6dacb8cb5786888592;p=xfstests-dev.git idmapped-mounts: Fix build error because of undefined reallocarray 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 Reviewed-by: Eryu Guan Signed-off-by: Eryu Guan --- diff --git a/configure.ac b/configure.ac index 0b55455a..6e5ab397 100644 --- a/configure.ac +++ b/configure.ac @@ -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 ]]) AC_CHECK_TYPES([struct btrfs_qgroup_limit], [], [], [[ #include diff --git a/src/idmapped-mounts/idmapped-mounts.c b/src/idmapped-mounts/idmapped-mounts.c index 4230cb48..83b7c89a 100644 --- a/src/idmapped-mounts/idmapped-mounts.c +++ b/src/idmapped-mounts/idmapped-mounts.c @@ -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;