Просмотр исходного кода

* Fixed upper limit in tbits.findnextbit, Mantis #25398.

git-svn-id: trunk@26754 -
sergei 11 лет назад
Родитель
Сommit
6c66b8ffe3
3 измененных файлов с 28 добавлено и 3 удалено
  1. 1 0
      .gitattributes
  2. 1 3
      rtl/objpas/classes/bits.inc
  3. 26 0
      tests/webtbs/tw25398.pp

+ 1 - 0
.gitattributes

@@ -13807,6 +13807,7 @@ tests/webtbs/tw25332a.pp svneol=native#text/plain
 tests/webtbs/tw25349.pp svneol=native#text/plain
 tests/webtbs/tw2536.pp svneol=native#text/plain
 tests/webtbs/tw25361.pp svneol=native#text/plain
+tests/webtbs/tw25398.pp svneol=native#text/plain
 tests/webtbs/tw2540.pp svneol=native#text/plain
 tests/webtbs/tw25494.pp svneol=native#text/plain
 tests/webtbs/tw25551.pp svneol=native#text/plain

+ 1 - 3
rtl/objpas/classes/bits.inc

@@ -319,16 +319,14 @@ end;
 function TBits.FindNextBit : longint;
 var
    loop : longint;
-   maxVal : longint;
 begin
    result := -1;  { will occur only if no other bits set to }
                   { current findState                        }
 
    if findIndex > -1 then { must have called FindFirstBit first }
    begin                  { or set the start index              }
-      maxVal := (FSize * 32) - 1;
 
-      for loop := findIndex + 1 to maxVal  do
+      for loop := findIndex + 1 to FBSize-1 do
       begin
          if get(loop) = findState then
          begin

+ 26 - 0
tests/webtbs/tw25398.pp

@@ -0,0 +1,26 @@
+{$mode objfpc}{$h+}
+uses classes;
+
+var
+  b: tbits;
+  i: integer;
+
+begin
+  b:= TBits.Create;
+  b.Size:= 128;
+  b.SetOn(0);
+  b.SetOn(13);
+  b.SetOn(118);
+  i:= b.FindFirstBit(True);
+  if i<>0 then
+    halt(1);
+  i:= b.FindNextBit;
+  if i<>13 then
+    halt(2);
+  i:= b.FindNextBit;
+  if i<>118 then
+    halt(3);
+  i:= b.FindNextBit;
+  if i<>-1 then
+    halt(4);
+end.