Sign in Join

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

Mailing lists / fpc-pascal / 2002-06

Ansistrings

9 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

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

Unknown author
Hello all,
  I have been having this issue since 0.9...  After heavy string manipulation on an ansistring it will crash the program with a RTE216 (general protection fault).  I don't particularly like pchars and i dislike them even more because it seems that when I need to convert the ansistring to a pchar (@ansistr[1]) it messes up.  Well really when I need to null terminate the ansistring with: ansist:=ansist+#0;

It sucks.. a lot. Please help.

- Matt

Unknown author

Here is the relevant code block that produces the GPF.

- see attached file -

Jonas Maebe
to Unknown author: I have been having this issue since 0.9... After heavy string manipulation on an…
I have been having this issue since 0.9...

Version 0.9 of the compiler?

Show quoted text 6 lines
After heavy string manipulation on an ansistring it will crash the program with a RTE216 (general protection fault). I don't particularly like pchars and i dislike them even more because it seems that when I need to convert the ansistring to a pchar (@ansistr[1]) it messes up. Well really when I need to null terminate the ansistring with: ansist:=ansist+#0;

Ansistrings are always null-terminated. You can "convert" an ansistring to a pchar simply by doing pchar(ansistring_var).

Jonas

Unknown author

I will try that. Thanks.

(But yes 0.9 of the compilier. I have brought a similar issue here a couple times before but with no real resolution)

Show quoted text 27 lines
On donderdag, juni 20, 2002, at 04:35 , wrote: > I have been having this issue since 0.9... Version 0.9 of the compiler? > After heavy string manipulation on an ansistring it will crash the > program with a RTE216 (general protection fault). I don't particularly > like pchars and i dislike them even more because it seems that when I > need to convert the ansistring to a pchar (@ansistr[1]) it messes up. > Well really when I need to null terminate the ansistring with: > ansist:=ansist+#0; Ansistrings are always null-terminated. You can "convert" an ansistring to a pchar simply by doing pchar(ansistring_var). Jonas _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Jonas Maebe
to Unknown author
I will try that. Thanks. (But yes 0.9 of the compilier. I have brought a similar issue here a couple times before but with no real resolution)

Have you tried compiling your program with -ghl?

Jonas

Unknown author

No I have not... I have not experimented much with the FPC debugging. The runtime errors are normally all I need and I can track the problem no sweat. At any rate...

The pchar(ansi_string_var) worked... but I am wondering why doing a astr:=astr+#0 would give it a GPF sometimes.  That is just weird to me.  Has anyone else had problems like this????

- Matt

Show quoted text 22 lines
On donderdag, juni 20, 2002, at 06:00 , wrote: > I will try that. Thanks. > > (But yes 0.9 of the compilier. I have brought a similar issue here a > couple times before but with no real resolution) Have you tried compiling your program with -ghl? Jonas _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Jonas Maebe
to Florian Klaempfl
Florian Klaempfl wrote 6 lines
>>Well really when I need to null terminate the ansistring with: >>ansist:=ansist+#0; > >Ansistrings are always null-terminated. Are you sure :) ?

Yes. There is no helper to convert an ansistring to a pchar (it's just a pointer to an ansirec that gets its type changed to a pointer to a char) and all ansistring handling routines in the RTL make sure all ansistrings are/remain null-terminated.

Jonas

Pierre Muller
to Jonas Maebe
Jonas Maebe wrote 13 lines
On Fri, 21 Jun 2002, Florian Klaempfl wrote: > >>Well really when I need to null terminate the ansistring with: > >>ansist:=ansist+#0; > > > >Ansistrings are always null-terminated. > > Are you sure :) ? Yes. There is no helper to convert an ansistring to a pchar (it's just a pointer to an ansirec that gets its type changed to a pointer to a char) and all ansistring handling routines in the RTL make sure all ansistrings are/remain null-terminated.

This is true, but don't forget that in constrast to pchar, ansistrings can contains #0 in the middle of a string... Thus printing an ansistring drectly or by
typecasting int into a pchar might
result in different outputs.