瀏覽代碼

* fix for bug web bug #7276: the code to read '*' format specifiers failed errorneously on Int64 and QWord input values. Based on code by mftq75
* test program for above changes

git-svn-id: trunk@4434 -

tom_at_work 19 年之前
父節點
當前提交
73d9beecff
共有 3 個文件被更改,包括 29 次插入5 次删除
  1. 1 0
      .gitattributes
  2. 10 5
      rtl/objpas/sysutils/sysformt.inc
  3. 18 0
      tests/webtbs/tw7276.pp

+ 1 - 0
.gitattributes

@@ -7263,6 +7263,7 @@ tests/webtbs/tw7143.pp -text
 tests/webtbs/tw7161.pp svneol=native#text/plain
 tests/webtbs/tw7195.pp svneol=native#text/plain
 tests/webtbs/tw7227.pp svneol=native#text/plain
+tests/webtbs/tw7276.pp svneol=native#text/plain
 tests/webtbs/ub1873.pp svneol=native#text/plain
 tests/webtbs/ub1883.pp svneol=native#text/plain
 tests/webtbs/uw0555.pp svneol=native#text/plain

+ 10 - 5
rtl/objpas/sysutils/sysformt.inc

@@ -19,7 +19,7 @@ Var ChPos,OldPos,ArgPos,DoArg,Len : SizeInt;
 
     Procedure ReadInteger;
 
-var Code: word;
+    var Code: Word;
 
     begin
       If Value<>-1 then exit; // Was already read.
@@ -30,10 +30,15 @@ var Code: word;
         DoFormatError(feInvalidFormat);
       If Fmt[Chpos]='*' then
         begin
-        If (Chpos>OldPos) or (ArgPos>High(Args))
-           or (Args[ArgPos].Vtype<>vtInteger) then
+        If (Chpos>OldPos) or (ArgPos>High(Args)) then
           DoFormatError(feInvalidFormat);
-        Value:=Args[ArgPos].VInteger;
+        case Args[ArgPos].Vtype of
+          vtInteger: Value := Args[ArgPos].VInteger;
+          vtInt64: Value := Args[ArgPos].VInt64^;
+          vtQWord: Value := Args[ArgPos].VQWord^;
+        else
+          DoFormatError(feInvalidFormat);
+        end;
         Inc(ArgPos);
         Inc(chPos);
         end
@@ -101,7 +106,7 @@ var Code: word;
       If Fmt[chpos]='.' then
         begin
         inc(chpos);
-        ReadInteger;
+          ReadInteger;
         If Value=-1 then
          Value:=0;
         prec:=Value;

+ 18 - 0
tests/webtbs/tw7276.pp

@@ -0,0 +1,18 @@
+uses Sysutils;
+
+var
+  s : AnsiString;
+
+begin
+  s := 'Hello';
+  // tests whether the * in the format specifier allows all
+  // kind of integers; note that the * in the format specifier here
+  // is an incomplete format specification, i.e. it does not change
+  // the length of the result string
+  Format('%*s', [Integer(length(s)), s]);
+  // this is only seemingly equivalent to above, but on 64 bit
+  // machines the default integer type is Int64
+  Format('%*s', [length(s), s])
+  // also test QWord
+  Format('%*s', [QWord(length(s)), s]);  
+end.