[PATCH v1 4/4] src/idmapped-mounts/idmapped-mounts.c: Fix build error because of undefined reallocarray

[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]



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@xxxxxxxxxxx>
---
 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 <linux/mount.h>]])
 AC_CHECK_TYPES([struct btrfs_qgroup_limit], [], [], [[
 #include <stddef.h>
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.23.0




[Index of Archives]     [Linux Filesystems Development]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux