From 83f9f983d95a4d5d1736ea6dacb8cb5786888592 Mon Sep 17 00:00:00 2001 From: Yang Xu Date: Wed, 1 Sep 2021 20:43:26 +0800 Subject: [PATCH] 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 --- configure.ac | 1 + src/idmapped-mounts/idmapped-mounts.c | 4 ++++ 2 files changed, 5 insertions(+) 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; -- 2.39.5