aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-04-03 15:05:14 +0200
committerChristian Grothoff <christian@grothoff.org>2020-04-03 15:05:14 +0200
commit4e259dbbba565c6f874ead9a8974175ffc6a2bb8 (patch)
treeb167294e23ce87c3cf0405b7d7bcb7204bae081b
parent1b5dfc396ced80c42516ab134e3fe4b340f08e2f (diff)
downloadgnunet-4e259dbbba565c6f874ead9a8974175ffc6a2bb8.tar.gz
gnunet-4e259dbbba565c6f874ead9a8974175ffc6a2bb8.zip
fix #6153
-rw-r--r--src/include/gnunet_common.h18
-rw-r--r--src/util/common_allocation.c20
2 files changed, 34 insertions, 4 deletions
diff --git a/src/include/gnunet_common.h b/src/include/gnunet_common.h
index 6e185c314..6d9652a16 100644
--- a/src/include/gnunet_common.h
+++ b/src/include/gnunet_common.h
@@ -1101,15 +1101,25 @@ GNUNET_ntoh_double (double d);
1101/** 1101/**
1102 * Check that memory in @a a is all zeros. @a a must be a pointer. 1102 * Check that memory in @a a is all zeros. @a a must be a pointer.
1103 * 1103 *
1104 * @param a pointer to @a n bytes which should be tested for the
1105 * entire memory being zero'ed out.
1106 * @param n number of bytes in @a to be tested
1107 * @return 0 if a is zero, non-zero otherwise
1108 */
1109int
1110GNUNET_is_zero_ (const void *a,
1111 size_t n);
1112
1113
1114/**
1115 * Check that memory in @a a is all zeros. @a a must be a pointer.
1116 *
1104 * @param a pointer to a struct which should be tested for the 1117 * @param a pointer to a struct which should be tested for the
1105 * entire memory being zero'ed out. 1118 * entire memory being zero'ed out.
1106 * @return 0 if a is zero, non-zero otherwise 1119 * @return 0 if a is zero, non-zero otherwise
1107 */ 1120 */
1108#define GNUNET_is_zero(a) \ 1121#define GNUNET_is_zero(a) \
1109 ({ \ 1122 GNUNET_is_zero_ (a, sizeof (a))
1110 static const typeof (*a) _z; \
1111 memcmp ((a), &_z, sizeof(_z)); \
1112 })
1113 1123
1114 1124
1115/** 1125/**
diff --git a/src/util/common_allocation.c b/src/util/common_allocation.c
index 35c557000..5945fdcde 100644
--- a/src/util/common_allocation.c
+++ b/src/util/common_allocation.c
@@ -533,4 +533,24 @@ GNUNET_copy_message (const struct GNUNET_MessageHeader *msg)
533} 533}
534 534
535 535
536/**
537 * Check that memory in @a a is all zeros. @a a must be a pointer.
538 *
539 * @param a pointer to @a n bytes which should be tested for the
540 * entire memory being zero'ed out.
541 * @param n number of bytes in @a to be tested
542 * @return 0 if a is zero, non-zero otherwise
543 */
544int
545GNUNET_is_zero_ (const void *a,
546 size_t n)
547{
548 const char *b = a;
549 for (size_t i = 0; i < n; i++)
550 if (b[i])
551 return 0;
552 return 1;
553}
554
555
536/* end of common_allocation.c */ 556/* end of common_allocation.c */