summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--stat.c7
-rw-r--r--util.h8
2 files changed, 14 insertions, 1 deletions
diff --git a/stat.c b/stat.c
index 47585b8..d223ff8 100644
--- a/stat.c
+++ b/stat.c
@@ -20,6 +20,7 @@
#include <errno.h>
#include <fcntl.h>
#include <stdbool.h>
+#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
@@ -161,6 +162,12 @@ static int bfs_stat_impl(int at_fd, const char *at_path, int at_flags, enum bfs_
* Wrapper for the statx() system call, which had no glibc wrapper prior to 2.28.
*/
static int bfs_statx(int at_fd, const char *at_path, int at_flags, unsigned int mask, struct statx *buf) {
+ // -fsanitize=memory doesn't know about statx(), so tell it the memory
+ // got initialized
+#if BFS_HAS_FEATURE(memory_sanitizer, false)
+ memset(buf, 0, sizeof(*buf));
+#endif
+
#if HAVE_STATX
return statx(at_fd, at_path, at_flags, mask, buf);
#else
diff --git a/util.h b/util.h
index d96b79d..6a51806 100644
--- a/util.h
+++ b/util.h
@@ -1,6 +1,6 @@
/****************************************************************************
* bfs *
- * Copyright (C) 2016-2018 Tavian Barnes <tavianator@tavianator.com> *
+ * Copyright (C) 2016-2019 Tavian Barnes <tavianator@tavianator.com> *
* *
* Permission to use, copy, modify, and/or distribute this software for any *
* purpose with or without fee is hereby granted. *
@@ -27,6 +27,12 @@
// Some portability concerns
+#ifdef __has_feature
+# define BFS_HAS_FEATURE(feature, fallback) __has_feature(feature)
+#else
+# define BFS_HAS_FEATURE(feature, fallback) fallback
+#endif
+
#ifdef __has_include
# define BFS_HAS_INCLUDE(header, fallback) __has_include(header)
#else