Possible bug in TROMacroParser.Eval

It looks like a bug may have been introduced in DataAbstract for Delphi build 1479 in method TROMacroParser.Eval (in unit uDAMacros.pas). The final else clause contains the following lines:

 if l > Length(r) then SetLength(r, l + LenInc);
  r[l] := p[i];
  inc(l);

where “r” is a TCharArray.

In previous builds the “inc(l)” was located before the other lines instead of after them, so r[l] would always be within the bounds of r. What happens now is that when l = Length(r), r[l] is past the end of the array. On the next pass, when l > Length(r), the most recently added Char gets overwritten with a #0 by the call to SetLength, resulting in a prematurely truncated string.

Hi,
you are right, it should be

if l >= Length(r) then SetLength(r, l + LenInc);

Thanks, logged as bugs://84462

bugs://84462 got closed with status fixed.