Module: kamailio
Branch: master
Commit: 42bae2a634249fe7d8ba174eaffff0ee547f6d2b
URL:
https://github.com/kamailio/kamailio/commit/42bae2a634249fe7d8ba174eaffff0e…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2024-01-10T13:45:30+01:00
registrar: cumpute randmized-range expire value as float and then cast
---
Modified: src/modules/registrar/sip_msg.c
---
Diff:
https://github.com/kamailio/kamailio/commit/42bae2a634249fe7d8ba174eaffff0e…
Patch:
https://github.com/kamailio/kamailio/commit/42bae2a634249fe7d8ba174eaffff0e…
---
diff --git a/src/modules/registrar/sip_msg.c b/src/modules/registrar/sip_msg.c
index 9ef2c37db47..69e8606fbc1 100644
--- a/src/modules/registrar/sip_msg.c
+++ b/src/modules/registrar/sip_msg.c
@@ -48,15 +48,17 @@ static struct hdr_field *act_contact;
*/
static inline int randomize_expires(int expires, int range)
{
- int range_min;
+ float range_min;
/* if no range is given just return expires */
if(range == 0)
return expires;
- range_min = expires - (float)range / 100 * expires;
+ range_min = (float)expires * (1.0 - ((float)range / 100));
- return range_min + (float)(kam_rand() % 100) / 100 * (expires - range_min);
+ return (int)(range_min
+ + ((float)(kam_rand() % 100) / 100)
+ * ((float)expires - range_min));
}