summaryrefslogtreecommitdiff
path: root/gl/lib
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2014-12-03 21:06:11 +0000
committerPádraig Brady <P@draigBrady.com>2014-12-03 23:38:36 +0000
commit5760532a2dcbad3569928f56a1d5d60d7282087c (patch)
treeca8b1343a13f3c53965bbbc302df4dcfb038cfc4 /gl/lib
parenta6d979299717e3769debfa5d295cb2934683077b (diff)
downloadcoreutils-5760532a2dcbad3569928f56a1d5d60d7282087c.tar.xz
maint: avoid -fsanitize=undefined warning in rand-isaac
* gl/lib/rand-isaac.c (isaac_refill): readisaac() purposefully passes unaligned pointers to avoid memory copies. This is only done on platforms where this is defined, so avoid the associated runtime warning generated with -fsanitize=undefined, which is: lib/rand-isaac.c:125:182: runtime error: store to misaligned address 0x63100003d7fd for type 'isaac_word', which requires 8 byte alignment 0x63100003d7fd: note: pointer points here 47 ce ed a4 be be be 00 00 00 00 00 00 00 00 ... ^
Diffstat (limited to 'gl/lib')
-rw-r--r--gl/lib/rand-isaac.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/gl/lib/rand-isaac.c b/gl/lib/rand-isaac.c
index c03242f66..3462b6d4b 100644
--- a/gl/lib/rand-isaac.c
+++ b/gl/lib/rand-isaac.c
@@ -35,6 +35,18 @@
#include "rand-isaac.h"
#include <limits.h>
+#include <string.h>
+
+/* If the platform supports unaligned access,
+ then don't have -fsanitize=undefined warn about it. */
+#undef ATTRIBUTE_NO_WARN_SANITIZE_UNDEFINED
+#if !_STRING_ARCH_unaligned \
+ || __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 9)
+# define ATTRIBUTE_NO_WARN_SANITIZE_UNDEFINED /* empty */
+#else
+# define ATTRIBUTE_NO_WARN_SANITIZE_UNDEFINED \
+ __attribute__ ((__no_sanitize_undefined__))
+#endif
/* The minimum of two sizes A and B. */
static inline size_t
@@ -81,7 +93,7 @@ ind (isaac_word const *m, isaac_word x)
}
/* Use and update *S to generate random data to fill RESULT. */
-void
+void ATTRIBUTE_NO_WARN_SANITIZE_UNDEFINED
isaac_refill (struct isaac_state *s, isaac_word result[ISAAC_WORDS])
{
/* Caches of S->a and S->b. */