[webkit-reviews] review granted: [Bug 237210] [Selection] Selection Range should be clamped by the current value length : [Attachment 453212] Patch

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Sun Feb 27 12:17:58 PST 2022


Darin Adler <darin at apple.com> has granted zsun at igalia.com's request for review:
Bug 237210: [Selection] Selection Range should be clamped by the current value
length
https://bugs.webkit.org/show_bug.cgi?id=237210

Attachment 453212: Patch

https://bugs.webkit.org/attachment.cgi?id=453212&action=review




--- Comment #2 from Darin Adler <darin at apple.com> ---
Comment on attachment 453212
  --> https://bugs.webkit.org/attachment.cgi?id=453212
Patch

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

> Source/WebCore/html/HTMLTextFormControlElement.cpp:283
> +    const int innerTextValueLength = innerTextValue().length();
> +    end = std::min(std::max(end, 0), std::max(innerTextValueLength, 0));
>      start = std::min(std::max(start, 0), end);

The "const" on the first line is not WebKit coding style. Most local variables
are constant, not reassigned, and we typically don’t put "const" in front of
all of them, although we could. I suggest writing this instead:

    constexpr unsigned maxInt = std::numeric_limits<int>::max();
    int innerTextValueLength = std::min(innerTextValue().length(), maxInt);
    end = std::clamp(end, 0, innerTextValueLength);
    start = std::clamp(start, 0, end);


More information about the webkit-reviews mailing list