[Lazarus] strcat problem
José Mejuto
joshyfun at gmail.com
Fri Jun 24 02:33:27 CEST 2016
El 23/06/2016 a las 21:08, Koenraad Lelong escribió:
> 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 ?
Hello,
Did you allocated the memory for the pchar ? Did you allocated memory
enough in target pchar to hold the large string after the strcat's ?
This code sample is wrong:
cTekst:=#13'text'#13;
strcat(cTekst,'other string');
The first assigns pchar to a read only memory block at compile time, and
at runtime next bytes (not allocated) are overwritten with "other
string" which will SIGSEGV for sure.
--
More information about the Lazarus
mailing list