RESOLVED FIXED 133592
Use unsigneds instead of ints for indexes into a string in text layout code
https://bugs.webkit.org/show_bug.cgi?id=133592
Summary Use unsigneds instead of ints for indexes into a string in text layout code
Myles C. Maxfield
Reported 2014-06-06 17:01:01 PDT
It would make more sense for it to return an unsigned.
Attachments
Patch (61.60 KB, patch)
2014-06-16 20:13 PDT, Myles C. Maxfield
no flags
Patch (89.10 KB, patch)
2014-06-17 10:21 PDT, Myles C. Maxfield
no flags
Patch (89.56 KB, patch)
2014-06-17 12:48 PDT, Myles C. Maxfield
no flags
Patch (89.59 KB, patch)
2014-06-20 16:12 PDT, Myles C. Maxfield
zalan: review+
Myles C. Maxfield
Comment 1 2014-06-16 20:13:34 PDT
Radar WebKit Bug Importer
Comment 2 2014-06-16 20:14:10 PDT
Myles C. Maxfield
Comment 3 2014-06-17 10:21:40 PDT
WebKit Commit Bot
Comment 4 2014-06-17 10:24:10 PDT
Attachment 233240 [details] did not pass style-queue: ERROR: Source/WebCore/rendering/svg/SVGTextRunRenderingContext.cpp:106: The parameter name "const" adds no information, so it should be removed. [readability/parameter_name] [5] Total errors found: 1 in 36 files If any of these errors are false positives, please file a bug against check-webkit-style.
Myles C. Maxfield
Comment 5 2014-06-17 10:40:29 PDT
*** Bug 133594 has been marked as a duplicate of this bug. ***
Brent Fulgham
Comment 6 2014-06-17 12:13:38 PDT
Comment on attachment 233240 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=233240&action=review > Source/WebCore/platform/graphics/Font.cpp:340 > + unsigned to = (initialTo == -1 ? run.length() : initialTo); Can initialTo ever be -2 (or lower)? Should this be "initialTo < 0 ?", as it is in 'drawEmphasisMarks'? > Source/WebCore/platform/graphics/Font.cpp:511 > + unsigned to = (initialTo == -1 ? run.length() : initialTo); Ditto above question. > Source/WebCore/platform/graphics/Font.cpp:1068 > + unsigned offsetInString = static_cast<unsigned>(initialOffsetInString); What if initialOffsetInString is negative?
Myles C. Maxfield
Comment 7 2014-06-17 12:36:21 PDT
Comment on attachment 233240 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=233240&action=review >> Source/WebCore/platform/graphics/Font.cpp:340 >> + unsigned to = (initialTo == -1 ? run.length() : initialTo); > > Can initialTo ever be -2 (or lower)? Should this be "initialTo < 0 ?", as it is in 'drawEmphasisMarks'? It shouldn't be, but it's simple enough to change the conditional. >> Source/WebCore/platform/graphics/Font.cpp:511 >> + unsigned to = (initialTo == -1 ? run.length() : initialTo); > > Ditto above question. Same answer. >> Source/WebCore/platform/graphics/Font.cpp:1068 >> + unsigned offsetInString = static_cast<unsigned>(initialOffsetInString); > > What if initialOffsetInString is negative? It should never be - the only negative value that it should ever have is -1 (kNoOffset). I'll add an assert for this.
Myles C. Maxfield
Comment 8 2014-06-17 12:48:22 PDT
WebKit Commit Bot
Comment 9 2014-06-17 12:50:26 PDT
Attachment 233253 [details] did not pass style-queue: ERROR: Source/WebCore/rendering/svg/SVGTextRunRenderingContext.cpp:106: The parameter name "const" adds no information, so it should be removed. [readability/parameter_name] [5] Total errors found: 1 in 36 files If any of these errors are false positives, please file a bug against check-webkit-style.
Myles C. Maxfield
Comment 10 2014-06-17 18:45:15 PDT
The style red bubble is a false negative, and it looks like the EFL bot was killed during compilation
alan
Comment 11 2014-06-20 11:12:42 PDT
Comment on attachment 233253 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=233253&action=review > Source/WebCore/rendering/InlineTextBox.cpp:202 > + if (endPos < m_start) if (endPos <= m_start) > Source/WebCore/rendering/InlineTextBox.cpp:204 > + unsigned ePos = std::min(endPos - m_start, static_cast<unsigned>(m_len)); Could you change m_len's type to unsigned too? I talked to Kling about it and while it was originally typed to be short to save memory, now with the simple line layout, we don't have that excessive amount of inlinetextboxes so it's ok to make it unsigned int. Its setter looks wrong too and can result in unsigned overflow: void setLen(unsigned len) { m_len = len; } So it's either the callers start using unsigned shorts or we make m_len unsigned int. -also, it's a bit odd that most of the inlinetextbox functions operate on ints while the length is short. It might be better though to have this m_len change in a separate patch. If it happens to bring in some major memory regression, we can easily revert it without undoing the signed-unsigned change. > Source/WebCore/rendering/InlineTextBox.cpp:278 > + if (endPos < m_start) same here. though now that I am seeing it the second time, it might be better to keep the old structure, though I don't feel too strongly about it. (shaving off a std::min() call vs. better code structuring (better code reading, less error prone))
alan
Comment 12 2014-06-20 11:12:43 PDT
Comment on attachment 233253 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=233253&action=review > Source/WebCore/rendering/InlineTextBox.cpp:202 > + if (endPos < m_start) if (endPos <= m_start) > Source/WebCore/rendering/InlineTextBox.cpp:204 > + unsigned ePos = std::min(endPos - m_start, static_cast<unsigned>(m_len)); Could you change m_len's type to unsigned too? I talked to Kling about it and while it was originally typed to be short to save memory, now with the simple line layout, we don't have that excessive amount of inlinetextboxes so it's ok to make it unsigned int. Its setter looks wrong too and can result in unsigned overflow: void setLen(unsigned len) { m_len = len; } So it's either the callers start using unsigned shorts or we make m_len unsigned int. -also, it's a bit odd that most of the inlinetextbox functions operate on ints while the length is short. It might be better though to have this m_len change in a separate patch. If it happens to bring in some major memory regression, we can easily revert it without undoing the signed-unsigned change. > Source/WebCore/rendering/InlineTextBox.cpp:278 > + if (endPos < m_start) same here. though now that I am seeing it the second time, it might be better to keep the old structure, though I don't feel too strongly about it. (shaving off a std::min() call vs. better code structuring (better code reading, less error prone))
Myles C. Maxfield
Comment 13 2014-06-20 15:53:48 PDT
Comment on attachment 233253 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=233253&action=review >>> Source/WebCore/rendering/InlineTextBox.cpp:204 >>> + unsigned ePos = std::min(endPos - m_start, static_cast<unsigned>(m_len)); >> >> Could you change m_len's type to unsigned too? >> I talked to Kling about it and while it was originally typed to be short to save memory, now with the simple line layout, we don't have that excessive amount of inlinetextboxes so it's ok to make it unsigned int. >> >> Its setter looks wrong too and can result in unsigned overflow: >> void setLen(unsigned len) { m_len = len; } >> So it's either the callers start using unsigned shorts or we make m_len unsigned int. -also, it's a bit odd that most of the inlinetextbox functions operate on ints while the length is short. >> >> It might be better though to have this m_len change in a separate patch. If it happens to bring in some major memory regression, we can easily revert it without undoing the signed-unsigned change. > > Could you change m_len's type to unsigned too? > I talked to Kling about it and while it was originally typed to be short to save memory, now with the simple line layout, we don't have that excessive amount of inlinetextboxes so it's ok to make it unsigned int. > > Its setter looks wrong too and can result in unsigned overflow: > void setLen(unsigned len) { m_len = len; } > So it's either the callers start using unsigned shorts or we make m_len unsigned int. -also, it's a bit odd that most of the inlinetextbox functions operate on ints while the length is short. > > It might be better though to have this m_len change in a separate patch. If it happens to bring in some major memory regression, we can easily revert it without undoing the signed-unsigned change. That's a good idea, but I do thing that that would be better to do in another patch. I designed this one to have no changed runtime characteristics.
alan
Comment 14 2014-06-20 16:04:19 PDT
(In reply to comment #13) > (From update of attachment 233253 [details]) > View in context: https://bugs.webkit.org/attachment.cgi?id=233253&action=review > > >>> Source/WebCore/rendering/InlineTextBox.cpp:204 > >>> + unsigned ePos = std::min(endPos - m_start, static_cast<unsigned>(m_len)); > >> > >> Could you change m_len's type to unsigned too? > >> I talked to Kling about it and while it was originally typed to be short to save memory, now with the simple line layout, we don't have that excessive amount of inlinetextboxes so it's ok to make it unsigned int. > >> > >> Its setter looks wrong too and can result in unsigned overflow: > >> void setLen(unsigned len) { m_len = len; } > >> So it's either the callers start using unsigned shorts or we make m_len unsigned int. -also, it's a bit odd that most of the inlinetextbox functions operate on ints while the length is short. > >> > >> It might be better though to have this m_len change in a separate patch. If it happens to bring in some major memory regression, we can easily revert it without undoing the signed-unsigned change. > > > > Could you change m_len's type to unsigned too? > > I talked to Kling about it and while it was originally typed to be short to save memory, now with the simple line layout, we don't have that excessive amount of inlinetextboxes so it's ok to make it unsigned int. > > > > Its setter looks wrong too and can result in unsigned overflow: > > void setLen(unsigned len) { m_len = len; } > > So it's either the callers start using unsigned shorts or we make m_len unsigned int. -also, it's a bit odd that most of the inlinetextbox functions operate on ints while the length is short. > > > > It might be better though to have this m_len change in a separate patch. If it happens to bring in some major memory regression, we can easily revert it without undoing the signed-unsigned change. > > That's a good idea, but I do thing that that would be better to do in another patch. I designed this one to have no changed runtime characteristics. On certain hw, going from signed to unsigned does change runtime characteristic, but I agree, it's better to do it in a separate patch.
Myles C. Maxfield
Comment 15 2014-06-20 16:12:11 PDT
Myles C. Maxfield
Comment 16 2014-06-20 16:14:11 PDT
(In reply to comment #14) > (In reply to comment #13) > > (From update of attachment 233253 [details] [details]) > > View in context: https://bugs.webkit.org/attachment.cgi?id=233253&action=review > > > > >>> Source/WebCore/rendering/InlineTextBox.cpp:204 > > >>> + unsigned ePos = std::min(endPos - m_start, static_cast<unsigned>(m_len)); > > >> > > >> Could you change m_len's type to unsigned too? > > >> I talked to Kling about it and while it was originally typed to be short to save memory, now with the simple line layout, we don't have that excessive amount of inlinetextboxes so it's ok to make it unsigned int. > > >> > > >> Its setter looks wrong too and can result in unsigned overflow: > > >> void setLen(unsigned len) { m_len = len; } > > >> So it's either the callers start using unsigned shorts or we make m_len unsigned int. -also, it's a bit odd that most of the inlinetextbox functions operate on ints while the length is short. > > >> > > >> It might be better though to have this m_len change in a separate patch. If it happens to bring in some major memory regression, we can easily revert it without undoing the signed-unsigned change. > > > > > > Could you change m_len's type to unsigned too? > > > I talked to Kling about it and while it was originally typed to be short to save memory, now with the simple line layout, we don't have that excessive amount of inlinetextboxes so it's ok to make it unsigned int. > > > > > > Its setter looks wrong too and can result in unsigned overflow: > > > void setLen(unsigned len) { m_len = len; } > > > So it's either the callers start using unsigned shorts or we make m_len unsigned int. -also, it's a bit odd that most of the inlinetextbox functions operate on ints while the length is short. > > > > > > It might be better though to have this m_len change in a separate patch. If it happens to bring in some major memory regression, we can easily revert it without undoing the signed-unsigned change. > > > > That's a good idea, but I do thing that that would be better to do in another patch. I designed this one to have no changed runtime characteristics. > On certain hw, going from signed to unsigned does change runtime characteristic, but I agree, it's better to do it in a separate patch. Really? Signed math isn't always the same speed as unsigned math on all hardware? I had no idea.
WebKit Commit Bot
Comment 17 2014-06-20 16:14:43 PDT
Attachment 233476 [details] did not pass style-queue: ERROR: Source/WebCore/rendering/svg/SVGTextRunRenderingContext.cpp:106: The parameter name "const" adds no information, so it should be removed. [readability/parameter_name] [5] Total errors found: 1 in 36 files If any of these errors are false positives, please file a bug against check-webkit-style.
Andreas Kling
Comment 18 2014-06-20 16:17:30 PDT
(In reply to comment #16) > > > That's a good idea, but I do thing that that would be better to do in another patch. I designed this one to have no changed runtime characteristics. > > On certain hw, going from signed to unsigned does change runtime characteristic, but I agree, it's better to do it in a separate patch. > > Really? Signed math isn't always the same speed as unsigned math on all hardware? I had no idea. ARMv7 doesn't have an instruction for signed modulo, for instance.
alan
Comment 19 2014-06-20 16:25:59 PDT
Comment on attachment 233476 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=233476&action=review > Source/WebCore/rendering/InlineTextBox.cpp:278 > + if (endPos < m_start) endPos <= m_start
Myles C. Maxfield
Comment 20 2014-06-22 10:18:27 PDT
WebKit Commit Bot
Comment 21 2014-06-22 11:05:55 PDT
Re-opened since this is blocked by bug 134174
Myles C. Maxfield
Comment 22 2014-06-23 17:31:01 PDT
The problem was a "<" vs a "<=". Re-landed in http://trac.webkit.org/changeset/170337.
Csaba Osztrogonác
Comment 23 2014-06-24 04:25:08 PDT
(In reply to comment #22) > The problem was a "<" vs a "<=". Re-landed in http://trac.webkit.org/changeset/170337. It made 3 tests crash on Apple Mac debug bots.
WebKit Commit Bot
Comment 24 2014-06-24 07:19:51 PDT
Re-opened since this is blocked by bug 134250
Myles C. Maxfield
Comment 25 2014-06-24 12:00:49 PDT
Having trouble reproducing locally :(
Myles C. Maxfield
Comment 26 2014-06-24 14:02:13 PDT
Was able to reproduce these, and the fix is trivial. I'll land again shortly. Hopefully this time it sticks.
Myles C. Maxfield
Comment 27 2014-06-24 14:05:04 PDT
Note You need to log in before you can comment on or make changes to this bug.