Re: kdiff3: FTBFS on hurd-i386 (for review)
- To: debian-hurd@lists.debian.org
- Subject: Re: kdiff3: FTBFS on hurd-i386 (for review)
- From: Svante Signell <svante.signell@gmail.com>
- Date: Fri, 31 Mar 2017 11:39:31 +0200
- Message-id: <[🔎] 1490953171.5172.10.camel@gmail.com>
- Reply-to: svante.signell@gmail.com
- In-reply-to: <667dbefc0788aa34b98fca2683f4c7cb@pino.toscano.name>
- References: <1411566672.28919.77.camel@G3620.my.own.domain> <20140924161132.GA91242@manta.lancelotsix.com> <5422FB45.304@qo.cx> <7216d5c075fee4da617a2701dee2672b@pino.toscano.name> <1411646733.28919.118.camel@G3620.my.own.domain> <667dbefc0788aa34b98fca2683f4c7cb@pino.toscano.name>
On Fri, 2014-09-26 at 07:44 +0200, Pino Toscano wrote:
> On 2014-09-25 14:05, Svante Signell wrote:
> > Hi Pino
> >
> > On Thu, 2014-09-25 at 10:08 +0200, Pino Toscano wrote:
> > > On 2014-09-24 19:11, Philipp A. Hartmann wrote:
> > > > I would probably do it like this (untested):
> > > >
> > > > const char *path =
> > > > QFile::encodeName(fi.absoluteFilePath()).constData();
> > >
> > > QFile::encodeName returns a temporary QByteArray, and getting a
> > > pointer to its internal char* will cause it to be a dangling
> > > pointer.
> > >
> > > const QByteArray path = QFile::encodeName(fi.absoluteFilePath());
> > >
> > > and then use path.constData() whenever needed.
> > >
> > > > std::vector<char> s(sb.st_size + 1);
> > >
> > > Please use QByteArray instead.
> >
> > Ok now?
>
> You've forgot the second part of what I said.
Hi again (2.5 years later). Attached is a patch using QByteArray. Hopefully it
is OK now? (I'm not fluent in C++)
Thanks!
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,22 @@ 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 QByteArray path = QFile::encodeName(fi.absoluteFilePath());
+ struct stat sb;
+ bool resolved = false;
+
+ if ( lstat(path.constData(), &sb) != -1 )
{
- s[len] = '\0';
- d()->m_linkTarget = QFile::decodeName(s);
+ QByteArray s = QByteArray(path.constData(), sb.st_size + 1);
+ ssize_t len = readlink(path.constData(), s.data(), s.size());
+ s[len] = '\0';
+ if ( len > 0 && len <= sb.st_size )
+ {
+ resolved = true;
+ d()->m_linkTarget = QFile::decodeName(s);
+ }
}
- else
+ if ( !resolved )
{
d()->m_linkTarget = fi.readLink();
}
Reply to: