diff options
Diffstat (limited to 'docs/checks/README-returning-data-from-temporary.md')
-rw-r--r-- | docs/checks/README-returning-data-from-temporary.md | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/docs/checks/README-returning-data-from-temporary.md b/docs/checks/README-returning-data-from-temporary.md new file mode 100644 index 00000000..efef86ed --- /dev/null +++ b/docs/checks/README-returning-data-from-temporary.md @@ -0,0 +1,31 @@ +# returning-data-from-temporary + +Warns when returning the data from a `QByteArray` that will soon be destroyed. + +## Examples +``` +QByteArray b = ...; +return b.data(); +``` +``` +return funcReturningByteArray().data(); +return funcReturningByteArray().constData(); +``` + + +``` +const char * getFoo() +{ + QByteArray b = ...; + return b; // QByteArray can implicitly cast to char* +} +``` + +``` + const char *c1 = getByteArray(); + const char *c2 = str.toUtf8().data(); +``` + +Note that in some cases it might be fine, since the method can return the data +of a global static QByteArray. However such code is brittle, it could start crashing +if it ceased to be static. |