aboutsummaryrefslogtreecommitdiff
path: root/src/mm-modem-helpers.h
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@aleksander.es>2020-01-30 18:54:23 +0100
committerAleksander Morgado <aleksander@aleksander.es>2020-01-31 15:18:35 +0100
commitbbeabb495e1bd2df3d938b850fbce4e61a61d9fa (patch)
treec2074f172166da03b5a20a4044a1ac2759523b2c /src/mm-modem-helpers.h
parentb856f3625db670346a248967a53d6d0119e725b7 (diff)
helpers: new macro to CLAMP high threshold only
Useful when clamping a unsigned integer with low threshold set to 0, which would give us compiler warnings with -Wtype-limits when using CLAMP(), e.g.: via/mm-broadband-modem-via.c: In function ‘handle_evdo_quality_change’: /usr/include/glib-2.0/glib/gmacros.h:811:63: error: comparison of unsigned expression < 0 is always false [-Werror=type-limits] 811 | #define CLAMP(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x))) | ^ via/mm-broadband-modem-via.c:284:19: note: in expansion of macro ‘CLAMP’ 284 | quality = CLAMP (quality, 0, 100); | ^~~~~
Diffstat (limited to 'src/mm-modem-helpers.h')
-rw-r--r--src/mm-modem-helpers.h6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/mm-modem-helpers.h b/src/mm-modem-helpers.h
index c41d1d31..9c1be81f 100644
--- a/src/mm-modem-helpers.h
+++ b/src/mm-modem-helpers.h
@@ -504,4 +504,10 @@ gboolean mm_parse_supl_address (const gchar *supl,
guint16 *out_port,
GError **error);
+/*****************************************************************************/
+
+/* Useful when clamp-ing an unsigned integer with implicit low limit set to 0,
+ * and in order to avoid -Wtype-limits warnings. */
+#define MM_CLAMP_HIGH(x, high) (((x) > (high)) ? (high) : (x))
+
#endif /* MM_MODEM_HELPERS_H */