[Qt] Qt fix for try..except in CopyUnicodeToPWideString()

Den Jean Den.Jean at telenet.be
Tue Jul 3 01:20:18 CEST 2007


On Tuesday 26 June 2007 05:17:28 pm zeljko wrote:
> Hi,
> I've located all problems and here is the fix.

nice :-)

> 1.Qt bindings (Den this is for you ;) ).

I am listening

>    bindhelp.h
>
> inline void copyQStringToPWideString(const QString &qs, PWideString ps)
> {
>    copyUnicodeToPWideString(qs.unicode(), ps, qs.length());
> }
>
>
> should be
>
> inline void copyQStringToPWideString(const QString &qs, PWideString ps)
> {
>    if (qs != 0 && ps)  /* we must check our params  */
>    copyUnicodeToPWideString(qs.unicode(), ps, qs.length());
> }

Like the "try...except...end;" trick this hides problems. 
("ps" should not be nil). We should first identify all problems. 

I already found one (no factory call on reference counted PWidestring)
and fixed it (i.e. V1.38)

You are better placed to verify if this resolves all the problems you could 
trigger. (I do not have any AVs in linux, my lcl program is too simple 
probably :-)

When we (euh you ;-) verified this really fixes it, I will add the param 
protection as default (now it is enclosed by a define). This will protect 
against providing nil as parameter in Pascal. I will also investigate if I 
can disallow this at compile time with "var Widestring", instead 
of "PWidestring" (ABI question)

>
> 2.qwidgets.pas in
>
> function TQtLineEdit.CreateWidget(const AParams: TCreateParams): QWidgetH;
>
>   Str := UTF8Decode((LCLObject as TCustomEdit).Text);
>   Result := QLineEdit_create(@Str, Parent);
>
>   should be
>
>   Str := UTF8Decode((LCLObject as TCustomEdit).Text);
>   if Length(Str) = 0 then
>   Str := #0;
>   Result := QLineEdit_create(@Str, Parent);

Did not look into this, tell me if it still exists

> I've founded only in QLineEdit that empty string initalization (length of
> Str is 0) raises AV.
>
> now, after recompiling bindings, and fix in TQtLineEdit constructor, you
> can remove try .. except and test.
>
> Any feedback is welcome ;)

thanks for all the great work.

> zeljko
>

regards,

Den Jean



More information about the Qt mailing list