trinity-devel@lists.pearsoncomputing.net

Message: previous - next
Month: February 2019

Re: [trinity-devel] Safe conversion TQString to char* in TQt3

From: "Michele Calgaro via trinity-devel" <trinity-devel@...>
Date: Mon, 4 Feb 2019 23:03:34 +0900
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

On 2019/02/04 03:50 AM, Sl�vek Banko wrote:
> Hi,
> 
> the purpose of the change is not to prevent bugs that programmers can do but to give the same scope for results
> from utf8() and local8Bit() as is for results from latin1() and ascii().
> 
> At the same time, the goal was to make the change so that there is no change in the public API.
> 
> The proposed change covers exactly these requirements. Nothing more, nothing less.
> 
> Cheers
> 
Hi Alexander, Slavek,
Slavek and I also don't like masking an issue and instead prefer to find the root cause whenever possible and practical.
The problem that we have with the current code is that although utf8() and local8bit() return valid TQCString objects,
it is extremely easy to run into problems when using the c_str() function of the return object in temporary
expressions, like for example when it is necessary to pass a const char* to a function. The error is subtle and shows
up at runtime instead of compile time, since syntactically the code is fine.

The solution proposed by Slavek makes the TQCString returned by utf8() and local8bit() persistent within the original
TQString. Although this will solve 99% of the use cases, it stills suffers of the original problem where if the
original TQString is a temporary object in a function call, the const char* would again point to an invalid object.

For R14.0.6 it makes somehow sense to go with Slavek's solution, to make things as less risky as possible without
actually affecting the API. We should though open an Issue in gitea so that this problem is not forgotten.
After R14.1.0 is out, we need to carefully consider various solutions and see which one is less intrusive and requires
the least API changes, but at the same time fixes the problem for good.

Cheers
  Michele
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCgAdFiEEjhl1z5vbYB3YbFTiKnW3yore1c8FAlxYRjYACgkQKnW3yore
1c9NLQ/9Hw2ZaB+mEUiQGFtbJI2Z8EjXqiazRLthNfBqvqLGzFfCAtSQ9vuhgxrd
KlDR4k+z22wk/v/ZwhHH3uCkTG5G4pxhBSH2pwI0J6+N8f+OMYOnPvUTys7VddPO
m1B0//nyVvnHFXw9WqdBWeYKsSToN/CYb0wPcZEr15wTVNOUUQFJCVLTKGfCTWOw
RDIhRUR2rcAsDp+9P5pbf7AW6xJtdGT1nOlPArH3fCRCI93G3NH5WldDv64e2ote
/BiATrVMp+lCjj6fHS7NnuKRCuCyB21NW5Xzpb62ZO/pVlnQveXSC5XCTALPO+gd
KnGOyqFZlFg+DM1ysR6O9pIc34poclU9ax3GapKBybrFveiyvaFK3xXvIs1esDvE
4hLx8KkYssPzwMh2EECKpCLX3ehdt5Tw8AqdWsWV7K8UXhhqvD5UOObrxO7j1THz
pIKXhWOXQr+d4jGQzc15msMvLdaNJ+QjWyLx2sFgpHGKmt5+g6yIsYxoUiz3AwrS
Q8w8ovMYWHFwgUON6RngyrmXUrOffuINNt4RatF0fPCmLmiey9WsNxPxoz0BWdBx
0z7IW+ONLFyF0Bax2BsMdty8FWPp39EOs32pePiKJorkH9QC5fbn7VDBpEfCZvE4
yUUEYuAyyCoPsrtJEmRU5gfqze4XsWXKa+eJEQKw1A0swBVHRGI=
=a+yX
-----END PGP SIGNATURE-----