]> git.ipfire.org Git - thirdparty/asterisk.git/commit
Use doubles instead of floats for conversions when comparing strings. 22/2822/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 20:24:33 +0000 (15:24 -0500)
commitfd3f70598d193d10bed997eaaea128a7bdbb2143
tree24842418361aa738399bcbdb1a03bfa81c7274d3
parentdd354009d3c64499640a0297703f5619e2cd5007
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