[Lazarus] strcat problem

Martin Grajcar maaartinus at gmail.com
Thu Jun 23 21:38:49 CEST 2016


Have you checked if there's any room behind #13'Now is the winter of our
discontent'#13, so that someone else's memory won't get overwritten? I'd
bet, there's none.

*Appends a copy of the source string to the destination string. The
terminating null character in destination is overwritten by the first
character of source, and a null-character is included at the end of the new
string formed by the concatenation of both in destination.*

You'd need something like
SetLength(cTekst, enoughToHoldThemAll);
and maybe also
cTekst[oldLength] := #0;
before the very first strcat.



On Thu, Jun 23, 2016 at 9:27 PM, Koenraad Lelong <lazarus2 at de-brouwerij.be>
wrote:

> Op 23-06-16 om 21:08 schreef Koenraad Lelong:
>
>> Op 23-06-16 om 16:58 schreef David W Noon:
>>
>>> [snip]
>>>
>>>> cTekst:=#13'Now is the winter of our discontent'#13;
>>>>
>>>
>>> You need a trailing #0 byte on the end.
>>>
>>>
>> The definition of cTekst :
>> var
>>     cTekst : PChar;
>>
>> So the compiler knows cTekst is a 0-terminated string doesn't, it ?
>> And StrCat needs two parameters : PChar and PChar. So I think the
>> compiler knows the strings are zero-terminated.
>> Besides, on my OpenSuse-box it works, or is that by chance ?
>>
>> Koenraad.
>>
>> Extra info :
> I checked with a hex-dumper (executables for opensuse & pi). All strings
> end with a #0. No byte-count in front of them. All start at a
> longword-boundary.
>
> Koenraad
>
>
> --
> _______________________________________________
> Lazarus mailing list
> Lazarus at lists.lazarus-ide.org
> http://lists.lazarus-ide.org/listinfo/lazarus
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20160623/bc2b3425/attachment-0002.html>


More information about the Lazarus mailing list