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);
| ^~~~~
This commit is contained in:
@@ -1674,12 +1674,8 @@ signal_state_query_ready (MbimDevice *device,
|
||||
NULL, /* rssi_threshold */
|
||||
NULL, /* error_rate_threshold */
|
||||
&error)) {
|
||||
guint32 quality;
|
||||
|
||||
/* Normalize the quality. 99 means unknown, we default it to 0 */
|
||||
quality = CLAMP (rssi == 99 ? 0 : (gint)rssi, 0, 31) * 100 / 31;
|
||||
|
||||
g_task_return_int (task, quality);
|
||||
g_task_return_int (task, MM_CLAMP_HIGH (rssi == 99 ? 0 : rssi, 31) * 100 / 31);
|
||||
} else
|
||||
g_task_return_error (task, error);
|
||||
|
||||
@@ -2920,7 +2916,7 @@ basic_connect_notification_signal_state (MMBroadbandModemMbim *self,
|
||||
guint32 quality;
|
||||
|
||||
/* Normalize the quality. 99 means unknown, we default it to 0 */
|
||||
quality = CLAMP (rssi == 99 ? 0 : (gint)rssi, 0, 31) * 100 / 31;
|
||||
quality = MM_CLAMP_HIGH (rssi == 99 ? 0 : rssi, 31) * 100 / 31;
|
||||
|
||||
mm_dbg ("Signal state indication: %u --> %u%%", rssi, quality);
|
||||
mm_iface_modem_update_signal_quality (MM_IFACE_MODEM (self), quality);
|
||||
|
||||
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user