On Wed, 2014-09-24 at 19:11 +0200, Philipp A. Hartmann wrote: > Hi, > > On 24/09/14 18:11, Lancelot SIX wrote:
Thank you both for your comments, and for teaching me C++ (I've never been fluent with it, learning new stuff every day). New patch attached. OK to submit?
Index: kdiff3-0.9.98/src-QT4/fileaccess.cpp =================================================================== --- kdiff3-0.9.98.orig/src-QT4/fileaccess.cpp +++ kdiff3-0.9.98/src-QT4/fileaccess.cpp @@ -235,14 +235,23 @@ void FileAccess::setFile( const QFileInf d()->m_linkTarget = fi.readLink(); #else // Unfortunately Qt4 readLink always returns an absolute path, even if the link is relative - char s[PATH_MAX+1]; - int len = readlink(QFile::encodeName(fi.absoluteFilePath()).constData(), s, PATH_MAX); - if ( len>0 ) + const char *path = + QFile::encodeName(fi.absoluteFilePath()).constData(); + struct stat sb; + bool resolved = false; + + if ( lstat(path, &sb) != -1 ) { - s[len] = '\0'; - d()->m_linkTarget = QFile::decodeName(s); + std::vector<char> s(sb.st_size + 1); + ssize_t len = readlink(path, &s[0], s.size()); + if ( len > 0 && len <= sb.st_size ) + { + resolved = true; + s[len] = '\0'; + d()->m_linkTarget = QFile::decodeName(&s[0]); + } } - else + if ( !resolved ) { d()->m_linkTarget = fi.readLink(); }