[webkit-reviews] review granted: [Bug 196935] Add an overflow check to HashTable : [Attachment 367492] Fixes the bug

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Mon Apr 15 21:17:20 PDT 2019

Geoffrey Garen <ggaren at apple.com> has granted Ryosuke Niwa <rniwa at webkit.org>'s
request for review:
Bug 196935: Add an overflow check to HashTable

Attachment 367492: Fixes the bug


--- Comment #3 from Geoffrey Garen <ggaren at apple.com> ---
Comment on attachment 367492
  --> https://bugs.webkit.org/attachment.cgi?id=367492
Fixes the bug

View in context: https://bugs.webkit.org/attachment.cgi?id=367492&action=review


> Source/WTF/wtf/HashTable.h:1206
> +	   Checked<unsigned, CrashOnOverflow> bestTableSize =
> +	   if (bestTableSize.unsafeGet() < keyCount)
> +	       bestTableSize.overflowed();
> +	   bestTableSize *= 2;

If we needed a check here, I would recommend doing using Checked<T>.

But we don't need this less-than check. roundUpToPowerOfTwo(2^32) is 2^32.
There's no overflow case.

I think I would write this as

    auto bestTableSize = Checked<unsigned,
CrashOnOverflow>(WTF::roundUpToPowerOfTwo(keyCount)) * 2;

More information about the webkit-reviews mailing list