]> git.ipfire.org Git - thirdparty/asterisk.git/commit
Use doubles instead of floats for conversions when comparing strings. 19/2819/1
authorMark Michelson <mmichelson@digium.com>
Thu, 12 May 2016 19:36:25 +0000 (14:36 -0500)
committerMark Michelson <mmichelson@digium.com>
Thu, 12 May 2016 19:36:25 +0000 (14:36 -0500)
commit02d30e171e439b52b0914ea87e427e175f371ad7
treee3cd6fd24e8f3ff66d43caefabebbc35513eace8
parenta01ce2b88912cd802bb045e40fe264906e55bc45
Use doubles instead of floats for conversions when comparing strings.

In 13.9.0, there was an issue where PJSIP contacts added to an AOR would
be deleted at seemingly random times.

One reason this was happening was because of an operation to retrieve
the contacts whose expiration time was less than or equal to the current
time. When retrieving existing contacts, the contact's expiration time
and the current time were converted from a string to a float, and those
two floats were compared.

On some systems, including mine, this conversion was horribly off. For
instance, I could regularly see the string "1463079214" get converted
into 1463079168.000000. When switching from using a float to using a
double, the conversion was as expected.

Why was the conversion to float off? My best guess is that the
conversion to float was attempting to store the entire value in the 23
bit significand of the IEEE-754 floating point number. In particular, if
you take only the 23 most significant bits of 1463079214, you get the
messed up 1463079168 that we were seeing in the conversion. It likely
was possible to get a more precise value by composing the number using
an exponent, but the conversion did not work that way. With a double,
you have a 52 bit significand, allowing the entire value to fit there,
and thereby allowing an accurate conversion.

ASTERISK-26007 #close
Reported by Greg Siemon

Change-Id: I83ca7944aae8b7cd994b254c78ec02411d321070
main/strings.c