Patch: Fix KEncodingProber crashiness

Jeff Mitchell mitchell at kde.org
Fri Mar 20 19:38:43 GMT 2009


Christoph Feck wrote:
> Am Friday 20 March 2009 19:25:57 schrieb Jeff Mitchell:
>> *Replaces the const char * pointer with a QString on the stack for safety.
>> *Replaces a strdup call with a QByteArray and a .data() call, which is not
>> strictly necessary but ensures that any safety checks in QByteArray are
>> handled.
>>
>> I'd like to put it in trunk and backport it for 4.2.2.
> 
> Who the heck designed this API?

I'm guessing whoever is holding the copyright in the header file :-)

> This here does not work, you are returning the address of a temporary,
> and the case when d->proper is non zero still uses strdup.
> 
> @@ -204,7 +203,7 @@
>  const char* KEncodingProber::encodingName() const
>  {
>      if (!d->prober)
> -        return strdup("UTF-8");
> +        return QByteArray("UTF-8").data();
>  
>      return strdup(d->prober->GetCharSetName());
>  }

Does the .data() call on a QByteArray return a temporary?  I thought it
returned a deep copy that was safe for e.g. passing outside of a function.

So, if QByteArray::data is returning the address of a temporary, do you
have a recommended Right Way(TM) fix?  Or should I simply return that
part to strdup?

Thanks,
Jeff

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 195 bytes
Desc: OpenPGP digital signature
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20090320/f5489b09/attachment.sig>


More information about the kde-core-devel mailing list