From 1d605ef47b77c5dc13de130ebbc8766fd456f68f Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Sat, 22 Sep 2012 01:06:34 +0200 Subject: [PATCH] FreeTDM: Add ftdm_clamp_safe() "Safer" version of ftdm_clamp(), that swaps min/max parameters if vmin happens to be larger than vmax, making sure the output will always satisfy vmin <= x <= vmax. Signed-off-by: Stefan Knoblich --- libs/freetdm/src/include/ftdm_os.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libs/freetdm/src/include/ftdm_os.h b/libs/freetdm/src/include/ftdm_os.h index d9d2b23205..c34810d241 100644 --- a/libs/freetdm/src/include/ftdm_os.h +++ b/libs/freetdm/src/include/ftdm_os.h @@ -87,6 +87,10 @@ typedef uint64_t ftdm_time_t; /*! \brief Get value that is in range [vmin,vmax] */ #define ftdm_clamp(val,vmin,vmax) ftdm_max(vmin,ftdm_min(val,vmax)) +/*!< \brief Safer version of ftdm_clamp(), that swaps vmin/vmax parameters if vmin > vmax */ +#define ftdm_clamp_safe(val,vmin,vmax) \ + ftdm_clamp(val, ftdm_min(vmin,vmax), ftdm_max(vmin,vmax)) + /*! * \brief Get offset of member in structure * \param[in] type Type of struct