[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-devel
Subject: Re: PATCH: kdelibs/kdecore/kstringhandler.cpp, prevent underflow
From: Alfons Hoogervorst <alfons () proteus ! demon ! nl>
Date: 2004-01-31 1:54:52
Message-ID: 20040131025452.69282213 () proteus ! demon ! nl
[Download RAW message or body]
Lo Alfons,
On 31-01-04 (Sat) 01:44 +0100 Alfons Hoogervorst
<alfons@proteus.demon.nl> wrote:
| CVS HEAD, but there may be already a fix in the original developer's
| local copy.
|
| Go to:
|
| http://better-scm.berlios.de/comparison/comparison.html#web_interface
|
| Open the "Yes: Vestaweb" link in a new tab.
|
| Result is 100% CPU usage because rightIdx is decremented without
| checking its lowerbound (0).
|
| Patch attached adds the lbound check.
Hmng. Not good enough.
Here's another underflow fix; plus the same checks in the outer loop
condition.
Surely the orginal developer comes with something better - looking
forward to it. :-)
Bye.
--
Ecuación algebraico sin solución posible,
a menos de poseer profundos conocimientos
en matemática - Revueltas (Ocho Por Radio)
["kdelibs.kdecore.kstringhandler.cpp.patch" (text/plain)]
Index: kdecore/kstringhandler.cpp
===================================================================
RCS file: /home/kde/kdelibs/kdecore/kstringhandler.cpp,v
retrieving revision 1.35
diff -u -r1.35 kstringhandler.cpp
--- kdecore/kstringhandler.cpp 29 Jan 2004 11:35:14 -0000 1.35
+++ kdecore/kstringhandler.cpp 31 Jan 2004 01:49:31 -0000
@@ -320,7 +320,9 @@
return s;
}
- const unsigned int maxWidth = width - fm.width( '.' ) * 3;
+ const unsigned int maxWidth = width > (uint) fm.width( '.') * 3
+ ? width - (uint) fm.width( '.' ) * 3
+ : width;
if ( maxWidth <= 0 ) {
return "...";
}
@@ -328,11 +330,11 @@
unsigned int leftIdx = 0, rightIdx = length;
unsigned int leftWidth = fm.charWidth( s, leftIdx++ );
unsigned int rightWidth = fm.charWidth( s, --rightIdx );
- while ( leftWidth + rightWidth < maxWidth ) {
- while ( leftWidth <= rightWidth && leftWidth + rightWidth < maxWidth ) {
+ while ( leftWidth + rightWidth < maxWidth && leftIdx < length && rightIdx > 0 ) {
+ while ( leftWidth <= rightWidth && leftWidth + rightWidth < maxWidth && leftIdx < length ) {
leftWidth += fm.charWidth( s, leftIdx++ );
}
- while ( rightWidth <= leftWidth && leftWidth + rightWidth < maxWidth ) {
+ while ( rightWidth <= leftWidth && leftWidth + rightWidth < maxWidth && rightIdx > 0 ) {
rightWidth += fm.charWidth( s, --rightIdx );
}
}
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic