aboutsummaryrefslogtreecommitdiffstats
path: root/src/checks/level1/README-returning-data-from-temporary.md
blob: efef86edbdfb69f4fd37d6a89ecf9e90ea035cb9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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.