I have a simple function which sends strings (uri links or filepaths) to an already running instance of the application using Qt's (5.5.1) QSharedMemory class.
It seems to work correctly for most of the times, but i caught a crash log from a user, where it crashed on a memcpy. The function looks the following:
void WindowsApp::SendData( char* uri )
{
int size = 1024;
if (!m_SharedMemory.create(size)) {
qDebug() << "Unable to create shared memory segment." << m_SharedMemory.error();
return;
}
m_SharedMemory.lock();
char *to = (char*)m_SharedMemory.data();
const char *from = uri;
memcpy(to, from, qMin(m_SharedMemory.size(), size));
m_SharedMemory.unlock();
QThread::sleep(10);
}
m_SharedMemory is a QSharedMemory type static member of the class.
From the log, i have seen that the string which i try to send is a simple filepath with no special characters, and not too long, only 150 chars.
What can be wrong , but so that i couldn't reproduce it with similar parameters?