mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-12 07:46:00 +02:00
* fix #40500: do a for-in on a string variable using low(strvar) to high(strvar) so that zero based strings are handled correctly
+ added test
This commit is contained in:
parent
5205ce30f4
commit
68668c649e
@ -586,8 +586,8 @@ implementation
|
|||||||
addstatement(loopbodystatement,hloopbody);
|
addstatement(loopbodystatement,hloopbody);
|
||||||
|
|
||||||
forloopnode:=cfornode.create(ctemprefnode.create(loopvar),
|
forloopnode:=cfornode.create(ctemprefnode.create(loopvar),
|
||||||
genintconstnode(1),
|
cinlinenode.createintern(in_low_x,false,ctemprefnode.create(stringvar)),
|
||||||
cinlinenode.create(in_length_x,false,ctemprefnode.create(stringvar)),
|
cinlinenode.create(in_high_x,false,ctemprefnode.create(stringvar)),
|
||||||
loopbody,
|
loopbody,
|
||||||
false);
|
false);
|
||||||
|
|
||||||
|
19
tests/webtbs/tw40500.pp
Normal file
19
tests/webtbs/tw40500.pp
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
program tw40500;
|
||||||
|
|
||||||
|
{$mode objfpc} {$h+} {$coperators+} {$zerobasedstrings+}
|
||||||
|
uses
|
||||||
|
SysUtils;
|
||||||
|
|
||||||
|
var
|
||||||
|
s: string;
|
||||||
|
c: char;
|
||||||
|
|
||||||
|
begin
|
||||||
|
s := '';
|
||||||
|
for c in string('share this to instantly die') do
|
||||||
|
if (c >= #32) and (c <= #127) then s += c else s += '#' + IntToStr(ord(c));
|
||||||
|
writeln(s);
|
||||||
|
if s <> 'share this to instantly die' then
|
||||||
|
Halt(1);
|
||||||
|
end.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user