[Webkit-unassigned] [Bug 183165] New: Delete incorrect version of clampTo() function from SVGToOTFFontConversion.cpp

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Tue Feb 27 10:24:43 PST 2018


https://bugs.webkit.org/show_bug.cgi?id=183165

            Bug ID: 183165
           Summary: Delete incorrect version of clampTo() function from
                    SVGToOTFFontConversion.cpp
           Product: WebKit
           Version: WebKit Nightly Build
          Hardware: Unspecified
                OS: Unspecified
            Status: NEW
          Severity: Normal
          Priority: P2
         Component: SVG
          Assignee: webkit-unassigned at lists.webkit.org
          Reporter: sabouhallawa at apple.com
                CC: zimmermann at kde.org

In SVGToOTFFontConversion.cpp, there many calls to the template function clampTo(). The first few of these calls, call the clampTo() from MathExtras.h. But the rest of these calls call the static clampTo() in SVGToOTFFontConversion.cpp:

// Assumption: T2 can hold every value that a T1 can hold.
template<typename T1, typename T2> static inline T1 clampTo(T2 x)
{
    x = std::min(x, static_cast<T2>(std::numeric_limits<T1>::max()));
    x = std::max(x, static_cast<T2>(std::numeric_limits<T1>::min()));
    return static_cast<T1>(x);
}

If we delete this function, all the calls in SVGToOTFFontConversion.cpp will be directed to the clampTo() in MathExtras.h. The results of the clampTo() in MathExtras.h will match the result of the deleted function expect one call which is the following:

append16(clampTo<uint16_t>(m_weight)); // Weight class

The reason is m_weight is char and the static clampTo() always returns 0 while the clampTo in MathExtras.h returns the m_weight casted to uint16_t. Here is the reason why the local clampTo() always returns 0.

1. std::numeric_limits<uint16_t>::min() is 0
2. std::numeric_limits<uint16_t>::max() is 65535
3. static_cast<char>(std::numeric_limits<uint16_t>::max()) is 255 or -1
4. std::min(x, static_cast<char>(std::numeric_limits<uint16_t>::max())) is -1 if x >= 0, or x if x < 0
5. std::max(x, static_cast<char>(std::numeric_limits<uint16_t>::min())) is 0 since x is always < 0

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20180227/0db32668/attachment.html>


More information about the webkit-unassigned mailing list