Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2015-01

strlower causes EAccessViolation

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Michael Van Ham

Hello,

The simple program below compiles and produces the expected output in 2.6.4. In 2.7.1 (3.1.1 now) an EAccessViolation is caused.

The strlower function seems to be in strings.inc and written in assembler. Unfortunately I can not decipher the assembly to research further.

---

program teststrlowersimple;
{$mode objfpc}
{$H+}
uses
  sysutils;
var
  s : string;
  p : pchar;
begin
  s := 'UPPPERCASESTRING';
  p := pchar(s);
  strlower(p); // EAccessViolation: Access violation
  writeln(s);
end.
Sven Barth
to Michael Van Ham
"Michael Van Ham" wrote
Hello, The simple program below compiles and produces the expected output in

2.6.4. In 2.7.1 (3.1.1 now) an EAccessViolation is caused.

The strlower function seems to be in strings.inc and written in

assembler. Unfortunately I can not decipher the assembly to research further.

Show quoted text 21 lines
--- program teststrlowersimple; {$mode objfpc} {$H+} uses sysutils; var s : string; p : pchar; begin s := 'UPPPERCASESTRING'; p := pchar(s); strlower(p); // EAccessViolation: Access violation writeln(s); end.

It's because in your example s points to a constant string which since 2.7.1 resides in a non-writeable section of the executable (Delphi compatible if I remember correctly). Instead of assigning a constant try for example "Readln(s)" or use UniqueString(s) (if I remember the function name correctly) after the assignment.

Regards,
Sven

Michael Van Ham
to Sven Barth
Sven Barth wrote 46 lines
Am 05.01.2015 21:33 schrieb "Michael Van Ham" : > > Hello, > > The simple program below compiles and produces the expected output in 2.6.4. In 2.7.1 (3.1.1 now) an EAccessViolation is caused. > > The strlower function seems to be in strings.inc and written in assembler. Unfortunately I can not decipher the assembly to research further. > > --- > > program teststrlowersimple; > > {$mode objfpc} > {$H+} > > uses > sysutils; > > var > s : string; > p : pchar; > > begin > s := 'UPPPERCASESTRING'; > p := pchar(s); > strlower(p); // EAccessViolation: Access violation > writeln(s); > end. It's because in your example s points to a constant string which since 2.7.1 resides in a non-writeable section of the executable (Delphi compatible if I remember correctly). Instead of assigning a constant try for example "Readln(s)" or use UniqueString(s) (if I remember the function name correctly) after the assignment. Regards, Sven _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Thank you for the explanation Sven!