diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2012-02-20 13:54:26 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2015-02-12 09:58:00 +0000 |
commit | d251cae7b7370af328307948aca9bb63def22fe4 (patch) | |
tree | e70c25f582e5e890e0886320d3899a8f460a156b /src/corelib/global | |
parent | 63114f4d3ce568e05346f7dba815b567da47894d (diff) |
Long live QString::asprintf()!
asprintf() is a GNU extension that prints into a string it
allocates internally. Arguably, that's a better name for
QString::sprintf() since it also allocates memory internally.
The main problem with QString::sprintf() isn't that it's
dangerous to use (it is), but that it's not static. It also
returns a reference instead of by-value, breaking RVO.
There is a comment about removing this function completely
in Qt 6.0, but it remains the only printf-style function
in Qt that can allocate the target string, so it's vital
for logging, e.g., and the recommended replacement code
(http://linux.die.net/man/3/vsnprintf) is a nightmare.
So this patch adds static (v)asprintf() methods to replace it.
Further patches will fix up all in-tree callers and finally
deprecate the old (v)sprintf().
Test coverage is provided through the existing tests of
sprintf(), which is implemented in terms of asprintf().
Arguably, the in-tree callers show that QByteArray would
benefit from having an asprintf(), too, as most of the
in-tree code works around its lack with calls
to to{Latin1,Local8Bit}() after using the QString version.
[ChangeLog][QtCore][QString] Added asprintf(), vasprintf().
Change-Id: I8510f8d67c22230653ec0f1c252c01bc95f3c386
Reviewed-by: Kai Koehne <kai.koehne@theqtcompany.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/global')
0 files changed, 0 insertions, 0 deletions