Menu

#12 Incorrect handling of filename in ScriptWindow::saveHDF5

open
nobody
None
5
2010-11-26
2010-11-26
Anonymous
No

The following code in scriptwindow.cpp is incorrect:

const char *fname = fileName.toAscii().constData();
H5Eset_auto(0,0);
hf = H5Fcreate(fname, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);

because QByteArray object created by fileName.toAscii is temporary and is destroyed after constData call. So pointer fname will point to unallocated memory region.
This behavior leads to the following problem: after 'saving as' new HDF5 file data are written to file with incorrect and spurious name.

The following fix is proposed:

QByteArray barray = fileName.toAscii();
const char *fname = barray.constData();

The discussion in Russian is here:
http://www.linux.org.ru/forum/development/5610360
http://www.linux.org.ru/forum/development/5612770

Discussion

MongoDB Logo MongoDB