aboutsummaryrefslogtreecommitdiff
path: root/src/lib/math
diff options
context:
space:
mode:
authorGeorge Kadianakis <desnacked@riseup.net>2019-03-21 20:57:42 +0200
committerNick Mathewson <nickm@torproject.org>2019-03-26 09:39:37 -0400
commit08176c239651656bf691f9414d037ab803be0fc0 (patch)
treed7637e514370fbe8b9261a83fc1bb49dd52f26de /src/lib/math
parentc81b2b09eadf8ee8775f61831db055425bcf7d27 (diff)
downloadtor-08176c239651656bf691f9414d037ab803be0fc0.tar.gz
tor-08176c239651656bf691f9414d037ab803be0fc0.zip
prob-distr: Silence some coverity warnings.
Diffstat (limited to 'src/lib/math')
-rw-r--r--src/lib/math/prob_distr.h15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/lib/math/prob_distr.h b/src/lib/math/prob_distr.h
index 66acb796fd..9b2ce41240 100644
--- a/src/lib/math/prob_distr.h
+++ b/src/lib/math/prob_distr.h
@@ -19,9 +19,22 @@ struct dist {
const struct dist_ops *ops;
};
+/** Assign the right ops to dist.dist_ops */
#define DIST_BASE(OPS) { .ops = (OPS) }
+
+/** A compile-time type-checking macro for use with DIST_BASE_TYPED. */
+#ifdef __COVERITY___
+/* Disable type-checking if coverity is enabled, since they don't like it */
+#define TYPE_CHECK_OBJ(OPS, OBJ, TYPE) 0
+#else
+#define TYPE_CHECK_OBJ(OPS, OBJ, TYPE) \
+ (0*sizeof(&(OBJ) - (const TYPE *)&(OBJ)))
+#endif
+
+/** Macro to initialize a distribution with the right OPS, while making sure
+ * that OBJ is of the right TYPE */
#define DIST_BASE_TYPED(OPS, OBJ, TYPE) \
- DIST_BASE((OPS) + 0*sizeof(&(OBJ) - (const TYPE *)&(OBJ)))
+ DIST_BASE((OPS) + TYPE_CHECK_OBJ(OPS,OBJ,TYPE))
const char *dist_name(const struct dist *);
double dist_sample(const struct dist *);