DoubleToStringConverter::ToExponential() should null terminate its string.
authormark.lam@apple.com <mark.lam@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 2 Oct 2019 23:20:56 +0000 (23:20 +0000)
committermark.lam@apple.com <mark.lam@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 2 Oct 2019 23:20:56 +0000 (23:20 +0000)
commit45efb957cbf8b84800256f03a9621c98125a55b8
tree1721b7ed2e66e35600c72c191f251f0cbda2a978
parente6a32ba8a1556554483b04554ec4c5315e855907
DoubleToStringConverter::ToExponential() should null terminate its string.
https://bugs.webkit.org/show_bug.cgi?id=202492
<rdar://problem/55907708>

Reviewed by Filip Pizlo.

JSTests:

* stress/dtoa-AddSubstring-should-uses-strnlen-in-assertion.js: Added.

Source/WTF:

* wtf/dtoa/double-conversion.cc:
- DoubleToStringConverter::DoubleToAscii() always produces a null terminated
  string.  Fixed the padding loop in DoubleToStringConverter::ToExponential()
  that follows it to also keep the null terminator.

* wtf/dtoa/utils.h:
(WTF::double_conversion::StringBuilder::AddSubstring):
- An assertion in here was using strlen() which indicates that it expects a null
  terminator in the incoming string.  However, this requirement is too restrictive.
  The code does not actually depend on the string having a null terminator, only
  that a null terminator does not manifest before the nth character.  Changed
  the assertion to use strnlen() instead to reflect this.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@250636 268f45cc-cd09-0410-ab3c-d52691b4dbfc
JSTests/ChangeLog
JSTests/stress/dtoa-AddSubstring-should-uses-strnlen-in-assertion.js [new file with mode: 0644]
Source/WTF/ChangeLog
Source/WTF/wtf/dtoa/double-conversion.cc
Source/WTF/wtf/dtoa/utils.h