Răsfoiți Sursa

* fixed strpos() in case source or target is nil
+ added test for this

git-svn-id: trunk@1907 -

Jonas Maebe 19 ani în urmă
părinte
comite
9b9dd342c5
3 a modificat fișierele cu 16 adăugiri și 0 ștergeri
  1. 1 0
      .gitattributes
  2. 2 0
      rtl/inc/stringsi.inc
  3. 13 0
      tests/test/tstring8.pp

+ 1 - 0
.gitattributes

@@ -5422,6 +5422,7 @@ tests/test/tstring4.pp svneol=native#text/plain
 tests/test/tstring5.pp svneol=native#text/plain
 tests/test/tstring6.pp svneol=native#text/plain
 tests/test/tstring7.pp svneol=native#text/plain
+tests/test/tstring8.pp svneol=native#text/plain
 tests/test/tstrreal1.pp svneol=native#text/plain
 tests/test/tstrreal2.pp svneol=native#text/plain
 tests/test/tsubdecl.pp svneol=native#text/plain

+ 2 - 0
rtl/inc/stringsi.inc

@@ -47,6 +47,8 @@
          lstr2 : SizeInt;
       begin
          strpos:=nil;
+         if (str1 = nil) or (str2 = nil) then
+           exit;
          p:=strscan(str1,str2^);
          if p=nil then
            exit;

+ 13 - 0
tests/test/tstring8.pp

@@ -0,0 +1,13 @@
+uses strings;
+
+var
+  a, b: pchar;
+
+begin
+  a := nil;
+  b := 'abc';
+  if (strpos(a,b) <> nil) or
+     (strpos(b,a) <> nil) or
+     (strpos(a,a) <> nil) then
+    halt(1);
+end.