Warning, /sdk/clazy/docs/checks/README-returning-data-from-temporary.md is written in an unsupported language. File is not indexed.
0001 # returning-data-from-temporary 0002 0003 Warns when returning the data from a `QByteArray` that will soon be destroyed. 0004 0005 ## Examples 0006 ``` 0007 QByteArray b = ...; 0008 return b.data(); 0009 ``` 0010 ``` 0011 return funcReturningByteArray().data(); 0012 return funcReturningByteArray().constData(); 0013 ``` 0014 0015 0016 ``` 0017 const char * getFoo() 0018 { 0019 QByteArray b = ...; 0020 return b; // QByteArray can implicitly cast to char* 0021 } 0022 ``` 0023 0024 ``` 0025 const char *c1 = getByteArray(); 0026 const char *c2 = str.toUtf8().data(); 0027 ``` 0028 0029 Note that in some cases it might be fine, since the method can return the data 0030 of a global static QByteArray. However such code is brittle, it could start crashing 0031 if it ceased to be static.