aboutsummaryrefslogtreecommitdiff
path: root/src/lib/intmath
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2018-06-28 13:19:42 -0400
committerNick Mathewson <nickm@torproject.org>2018-06-28 13:19:42 -0400
commit3d1e99d01bc0142397cd0dd8be41d001f0f66131 (patch)
treee4f9721aeaeeae583c25bfdfa9544e0b64aee9de /src/lib/intmath
parent8736892679eabeecfa87f9bf19ac22245dc711c0 (diff)
downloadtor-3d1e99d01bc0142397cd0dd8be41d001f0f66131.tar.gz
tor-3d1e99d01bc0142397cd0dd8be41d001f0f66131.zip
Move MIN and MAX into lib/intmath/cmp.h
Diffstat (limited to 'src/lib/intmath')
-rw-r--r--src/lib/intmath/cmp.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/lib/intmath/cmp.h b/src/lib/intmath/cmp.h
index 90ea3ca079..627e5d18b4 100644
--- a/src/lib/intmath/cmp.h
+++ b/src/lib/intmath/cmp.h
@@ -6,6 +6,19 @@
#ifndef TOR_INTMATH_CMP_H
#define TOR_INTMATH_CMP_H
+/** Macros for MIN/MAX. Never use these when the arguments could have
+ * side-effects.
+ * {With GCC extensions we could probably define a safer MIN/MAX. But
+ * depending on that safety would be dangerous, since not every platform
+ * has it.}
+ **/
+#ifndef MAX
+#define MAX(a,b) ( ((a)<(b)) ? (b) : (a) )
+#endif
+#ifndef MIN
+#define MIN(a,b) ( ((a)>(b)) ? (b) : (a) )
+#endif
+
/* Return <b>v</b> if it's between <b>min</b> and <b>max</b>. Otherwise
* return <b>min</b> if <b>v</b> is smaller than <b>min</b>, or <b>max</b> if
* <b>b</b> is larger than <b>max</b>.