[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor/master] prob-distr: Silence some coverity warnings.
commit 08176c239651656bf691f9414d037ab803be0fc0
Author: George Kadianakis <desnacked@xxxxxxxxxx>
Date: Thu Mar 21 20:57:42 2019 +0200
prob-distr: Silence some coverity warnings.
---
changes/bug29805 | 3 +++
src/lib/math/prob_distr.h | 15 ++++++++++++++-
2 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/changes/bug29805 b/changes/bug29805
new file mode 100644
index 000000000..00c846e9a
--- /dev/null
+++ b/changes/bug29805
@@ -0,0 +1,3 @@
+ o Minor bugfixes (probability distributions):
+ - Refactor and improve parts of the probability distribution code that made
+ Coverity complain. Fixes bug 29805; bugfix on 0.4.0.1-alpha.
\ No newline at end of file
diff --git a/src/lib/math/prob_distr.h b/src/lib/math/prob_distr.h
index 66acb796f..9b2ce4124 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 *);
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits