View Issue Details

IDProjectCategoryView StatusLast Update
0027028LazarusWidgetsetpublic2015-09-02 16:57
ReporterPetr-KAssigned ToJesus Reyes 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
PlatformWin32OSWinXPOS Version
Product Version1.3 (SVN)Product Buildtrunk #46763 
Target Version1.4Fixed in Version1.4 
Summary0027028: Range check in TWin32WidgetSet.DrawText
DescriptionThere is problem in the commit 46561 by jesus. Related to 0023313

If DrawText argument Str is not only ascii text and font is italic, then I get Range check error on line:
 res := GetCharABCWidthsW(DC, Uint(W[Count-1]), Uint(W[Count-1]), paABC)

Problem is in W[Count-1].
In this case Count > Length(W), because argument Count is number of chars.

Included patch solves it.

---

Another remark:
I think that argument for GetCharABCWidthsW should be W[Count] (last character) instead of W[Count-1] (before last character)

TagsNo tags attached.
Fixed in Revision 46835
LazTarget1.4
WidgetsetWin32/Win64
Attached Files
  • win32winapi.patch (852 bytes)
    Index: win32winapi.inc
    ===================================================================
    --- win32winapi.inc	(revision 46763)
    +++ win32winapi.inc	(working copy)
    @@ -1135,6 +1135,7 @@
       lf: LOGFONT;
       aABC: ABC;
       paABC: LPABC;
    +  c: Integer;
     {$endif}
     begin
      {$ifdef WindowsUnicodeSupport}
    @@ -1180,10 +1181,12 @@
         begin
     
           paABC := @aABC;
    -      if UnicodeEnabledOS then
    -        res := GetCharABCWidthsW(DC, Uint(W[Count-1]), Uint(W[Count-1]), paABC)
    +      if UnicodeEnabledOS then begin
    +        c := Length(W);
    +        res := GetCharABCWidthsW(DC, Uint(W[c]), Uint(W[c]), paABC)
    +      end
           else
    -        res := GetCharABCWidthsA(DC, ord(s[Count-1]), ord(s[Count-1]), paABC);
    +        res := GetCharABCWidthsA(DC, ord(s[Count]), ord(s[Count]), paABC);
     
          if res then
            Rect.Right := Rect.Right + Abs(aABC.abcC);
    
    win32winapi.patch (852 bytes)

Relationships

has duplicate 0027033 closedBart Broersma [Regression] Range check error when painting a 1-character string in italic 

Activities

Petr-K

2014-11-11 17:18

reporter  

win32winapi.patch (852 bytes)
Index: win32winapi.inc
===================================================================
--- win32winapi.inc	(revision 46763)
+++ win32winapi.inc	(working copy)
@@ -1135,6 +1135,7 @@
   lf: LOGFONT;
   aABC: ABC;
   paABC: LPABC;
+  c: Integer;
 {$endif}
 begin
  {$ifdef WindowsUnicodeSupport}
@@ -1180,10 +1181,12 @@
     begin
 
       paABC := @aABC;
-      if UnicodeEnabledOS then
-        res := GetCharABCWidthsW(DC, Uint(W[Count-1]), Uint(W[Count-1]), paABC)
+      if UnicodeEnabledOS then begin
+        c := Length(W);
+        res := GetCharABCWidthsW(DC, Uint(W[c]), Uint(W[c]), paABC)
+      end
       else
-        res := GetCharABCWidthsA(DC, ord(s[Count-1]), ord(s[Count-1]), paABC);
+        res := GetCharABCWidthsA(DC, ord(s[Count]), ord(s[Count]), paABC);
 
      if res then
        Rect.Right := Rect.Right + Abs(aABC.abcC);
win32winapi.patch (852 bytes)

Jesus Reyes

2014-11-13 16:21

developer   ~0079133

Initially I used pointers to widechar and char respectively, then switched to strings and forgot the index :(.

Thanks Applied with changes.

Petr-K

2015-09-02 16:57

reporter   ~0085671

works

Issue History

Date Modified Username Field Change
2014-11-11 17:18 Petr-K New Issue
2014-11-11 17:18 Petr-K File Added: win32winapi.patch
2014-11-13 12:19 Bart Broersma Relationship added has duplicate 0027033
2014-11-13 15:35 Jesus Reyes Assigned To => Jesus Reyes
2014-11-13 15:35 Jesus Reyes Status new => assigned
2014-11-13 16:21 Jesus Reyes Fixed in Revision => 46835
2014-11-13 16:21 Jesus Reyes LazTarget => 1.4
2014-11-13 16:21 Jesus Reyes Note Added: 0079133
2014-11-13 16:21 Jesus Reyes Status assigned => resolved
2014-11-13 16:21 Jesus Reyes Fixed in Version => 1.4
2014-11-13 16:21 Jesus Reyes Resolution open => fixed
2014-11-13 16:21 Jesus Reyes Target Version => 1.4
2015-09-02 16:57 Petr-K Note Added: 0085671
2015-09-02 16:57 Petr-K Status resolved => closed