Skip to content

Commit

Permalink
Merge pull request #230 from ffontaine/main
Browse files Browse the repository at this point in the history
libcomposefs/lcfs-writer.c: fix build without reallocarray
  • Loading branch information
alexlarsson authored Dec 11, 2023
2 parents 38564f4 + 3358d54 commit 249193a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ AC_FUNC_ERROR_AT_LINE
AC_FUNC_FSEEKO
AC_HEADER_MAJOR
AC_FUNC_MMAP
AC_CHECK_FUNCS([getcwd memset munmap strdup])
AC_CHECK_FUNCS([getcwd memset munmap reallocarray strdup])

AC_SUBST(PKGCONFIG_REQUIRES)
AC_SUBST(PKGCONFIG_REQUIRES_PRIVATELY)
Expand Down
15 changes: 15 additions & 0 deletions libcomposefs/lcfs-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,21 @@ static inline char *memdup(const char *s, size_t len)
return s2;
}

static inline bool size_multiply_overflow(size_t size, size_t nmemb)
{
return nmemb != 0 && size > (SIZE_MAX / nmemb);
}

#ifndef HAVE_REALLOCARRAY
static inline void *reallocarray(void *ptr, size_t nmemb, size_t size)
{
if (size_multiply_overflow(size, nmemb))
return NULL;

return realloc(ptr, size * nmemb ?: 1);
}
#endif

static inline int hexdigit(char c)
{
if (c >= '0' && c <= '9')
Expand Down

0 comments on commit 249193a

Please sign in to comment.