[lazarus] Patch for Win32 interface

Martin Smat martin.smat at tiscali.cz
Thu Jul 31 15:20:47 EDT 2003


Marc Weustink napsal(a):
> 
> EEEEEEK !
> 
> 
> At 18:37 30-7-2003 +0200, Martin Smat wrote:
> 
>> Hi,
>> attached patch adds LM_APPENDTEXT message used by TMemo. This message 
>> is called when a new line is added into a memobox.
>>
>> But I have a problem when the memo is cleared (memo.text:=''). Allways 
>> the firs line is not removed.
>>
>> Martin Smat.
>>
>>
>> diff -c old\win32object.inc new\win32object.inc
>> *** old\win32object.inc Tue Jul 29 18:14:54 2003
>> --- new\win32object.inc Wed Jul 30 18:24:46 2003
>> ***************
>> *** 409,414 ****
>> --- 409,420 ----
>>       LM_ATTACHMENU:
>>         AttachMenu(Sender);
>>           //SH: think of TBitmap.handle!!!!
>> +     LM_APPENDTEXT:
>> +     Begin
>> +       PStr:=PChar((Sender as TMemo).Text);
>> +       StrCat(PStr, Data);
>> +       SetLabel(Sender, PStr);
> 
> 
> Don't do this !
> 
> StrCat just concatinates 2 destination and source buffer and puts the 
> result in the destination buffer.
> 
> *without length checking*
> *without buffer allocation*
> 
> what do we have: one casted string with enough room to hold itself used 
> as destination and one buffer of data to be apended.
> 
> what do we get: a nice bufferoverrun !
> 
> Just this weekend there was a discussion about the dos and donts 
> concerning strings and pchars. This is don't !
> 
> Solution: use a string as temp buffer
> 
> 
>   S := (Sender as TMemo).Text + PChar(Data);
>   SetLabel(Sender, PChar(S));
> 
> Marc (update is in CVS)

Thank you for this correction. Next time I must be more carefull.

Martin.






More information about the Lazarus mailing list