Commit bd24a6a3 authored by Michael Reeves's avatar Michael Reeves

Resolve 64 bit to 32 bit convertion

The code is now almost completely 64 bit safe for large files. The sole
exeption being two QByteArray contructor calls. The size limit for files
is 1GB until this is resolved.
parent e60178a8
......@@ -285,7 +285,7 @@ int SourceData::getSizeLines() const
return m_normalData.m_vSize;
}
int SourceData::getSizeBytes() const
qint64 SourceData::getSizeBytes() const
{
return m_normalData.m_size;
}
......@@ -459,7 +459,15 @@ static QTextCodec* detectEncoding(const char* buf, qint64 size, qint64& skipByte
}
}
skipBytes = 0;
QByteArray s(buf, size);
QByteArray s;
/*
We don't need the whole file here just the header.
] */
if(size <= 5000)
s=QByteArray(buf, (int)size);
else
s=QByteArray(buf, 5000);
int xmlHeaderPos = s.indexOf("<?xml");
if(xmlHeaderPos >= 0)
{
......@@ -656,7 +664,7 @@ QStringList SourceData::readAndPreprocess(QTextCodec* pEncoding, bool bAutoDetec
m_lmppData.reset();
FileAccess faIn(fileNameIn1);
int fileInSize = faIn.size();
qint64 fileInSize = faIn.size();
if(faIn.exists()) // fileInSize > 0 )
{
......@@ -876,7 +884,7 @@ void SourceData::FileData::preprocess(bool bPreserveCR, QTextCodec* pEncoding)
QTextCodec* pCodec = ::detectEncoding(m_pBuf, m_size, skipBytes);
if(pCodec != pEncoding)
skipBytes = 0;
QByteArray ba = QByteArray::fromRawData(m_pBuf + skipBytes, m_size - skipBytes);
QTextStream ts(ba, QIODevice::ReadOnly | QIODevice::Text);
ts.setCodec(pEncoding);
......@@ -1571,9 +1579,9 @@ static bool runDiff(const LineData* p1, int size1, const LineData* p2, int size2
gnuDiff.ignore_case = false;
GnuDiff::change* script = gnuDiff.diff_2_files(&comparisonInput);
int equalLinesAtStart = comparisonInput.file[0].prefix_lines;
int currentLine1 = 0;
int currentLine2 = 0;
lin equalLinesAtStart = comparisonInput.file[0].prefix_lines;
lin currentLine1 = 0;
lin currentLine2 = 0;
GnuDiff::change* p = nullptr;
for(GnuDiff::change* e = script; e; e = p)
{
......@@ -1618,7 +1626,7 @@ static bool runDiff(const LineData* p1, int size1, const LineData* p2, int size2
currentLine1 += equalLinesAtStart;
currentLine2 += equalLinesAtStart;
int nofEquals = min2(size1 - currentLine1, size2 - currentLine2);
lin nofEquals = min2(size1 - currentLine1, size2 - currentLine2);
if(nofEquals == 0)
{
diffList.back().diff1 += size1 - currentLine1;
......@@ -1646,8 +1654,8 @@ static bool runDiff(const LineData* p1, int size1, const LineData* p2, int size2
// Verify difflist
{
int l1 = 0;
int l2 = 0;
lin l1 = 0;
lin l2 = 0;
DiffList::iterator i;
for(i = diffList.begin(); i != diffList.end(); ++i)
{
......
......@@ -24,18 +24,19 @@
#include "common.h"
#include "fileaccess.h"
#include "options.h"
#include "gnudiff_diff.h"
// Each range with matching elements is followed by a range with differences on either side.
// Then again range of matching elements should follow.
struct Diff
{
int nofEquals;
lin nofEquals;
int diff1;
int diff2;
qint64 diff1;
qint64 diff2;
Diff(int eq, int d1, int d2){nofEquals=eq; diff1=d1; diff2=d2; }
Diff(lin eq, qint64 d1, qint64 d2){nofEquals=eq; diff1=d1; diff2=d2; }
};
typedef std::list<Diff> DiffList;
......@@ -247,7 +248,7 @@ public:
void setOptions( Options* pOptions );
int getSizeLines() const;
int getSizeBytes() const;
qint64 getSizeBytes() const;
const char* getBuf() const;
const QString& getText() const;
const LineData* getLineDataForDisplay() const;
......@@ -291,7 +292,7 @@ private:
FileData(){ m_pBuf=nullptr; m_size=0; m_vSize=0; m_bIsText=false; m_eLineEndStyle=eLineEndStyleUndefined; m_bIncompleteConversion=false;}
~FileData(){ reset(); }
const char* m_pBuf;
int m_size;
qint64 m_size;
int m_vSize; // Nr of lines in m_pBuf1 and size of m_v1, m_dv12 and m_dv13
QString m_unicodeBuf;
QVector<LineData> m_v;
......
......@@ -884,7 +884,7 @@ bool DirectoryMergeWindow::Data::fastFileComparison(
while(sizeLeft > 0 && !pp.wasCancelled())
{
int len = min2(sizeLeft, (t_FileSize)buf1.size());
qint64 len = min2(sizeLeft, (t_FileSize)buf1.size());
if(len != file1.read(&buf1[0], len))
{
status = i18n("Error reading from %1", fileName1);
......
......@@ -419,7 +419,7 @@ void FileAccess::setUdsEntry(const KIO::UDSEntry& e)
m_filePath = e.stringValue(f);
break; // During listDir the relative path is given here.
case KIO::UDSEntry::UDS_MODIFICATION_TIME:
m_modificationTime.setTime_t(e.numberValue(f));
m_modificationTime = QDateTime::fromMSecsSinceEpoch(e.numberValue(f));
break;
//case KIO::UDSEntry::UDS_ACCESS_TIME : d()->m_accessTime.setTime_t( e.numberValue(f) ); break;
//case KIO::UDSEntry::UDS_CREATION_TIME : d()->m_creationTime.setTime_t( e.numberValue(f) ); break;
......@@ -690,16 +690,16 @@ QDateTime FileAccess::lastRead() const
}
*/
static bool interruptableReadFile(QFile& f, void* pDestBuffer, unsigned long maxLength)
static bool interruptableReadFile(QFile& f, void* pDestBuffer, qint64 maxLength)
{
ProgressProxy pp;
const unsigned long maxChunkSize = 100000;
unsigned long i = 0;
const qint64 maxChunkSize = 100000;
qint64 i = 0;
pp.setMaxNofSteps(maxLength / maxChunkSize + 1);
while(i < maxLength)
{
unsigned long nextLength = min2(maxLength - i, maxChunkSize);
unsigned long reallyRead = f.read((char*)pDestBuffer + i, nextLength);
qint64 nextLength = min2(maxLength - i, maxChunkSize);
qint64 reallyRead = f.read((char*)pDestBuffer + i, nextLength);
if(reallyRead != nextLength)
{
return false;
......@@ -713,7 +713,7 @@ static bool interruptableReadFile(QFile& f, void* pDestBuffer, unsigned long max
return true;
}
bool FileAccess::readFile(void* pDestBuffer, unsigned long maxLength)
bool FileAccess::readFile(void* pDestBuffer, qint64 maxLength)
{
if(d() != nullptr && !d()->m_localCopy.isEmpty())
{
......@@ -736,7 +736,7 @@ bool FileAccess::readFile(void* pDestBuffer, unsigned long maxLength)
return false;
}
bool FileAccess::writeFile(const void* pSrcBuffer, unsigned long length)
bool FileAccess::writeFile(const void* pSrcBuffer, qint64 length)
{
ProgressProxy pp;
if(isLocal())
......@@ -744,13 +744,13 @@ bool FileAccess::writeFile(const void* pSrcBuffer, unsigned long length)
QFile f(absoluteFilePath());
if(f.open(QIODevice::WriteOnly))
{
const unsigned long maxChunkSize = 100000;
const qint64 maxChunkSize = 100000;
pp.setMaxNofSteps(length / maxChunkSize + 1);
unsigned long i = 0;
qint64 i = 0;
while(i < length)
{
unsigned long nextLength = min2(length - i, maxChunkSize);
unsigned long reallyWritten = f.write((char*)pSrcBuffer + i, nextLength);
qint64 nextLength = min2(length - i, maxChunkSize);
qint64 reallyWritten = f.write((char*)pSrcBuffer + i, nextLength);
if(reallyWritten != nextLength)
{
return false;
......@@ -1011,7 +1011,7 @@ bool FileAccessJobHandler::get(void* pDestBuffer, long maxLength)
connect(pJob, &KIO::TransferJob::result, this, &FileAccessJobHandler::slotSimpleJobResult);
connect(pJob, &KIO::TransferJob::data, this, &FileAccessJobHandler::slotGetData);
connect(pJob, SIGNAL(percent(KJob*, unsigned long)), &pp, SLOT(slotPercent(KJob*, unsigned long)));
connect(pJob, SIGNAL(percent(KJob*, qint64)), &pp, SLOT(slotPercent(KJob*, qint64)));
ProgressProxy::enterEventLoop(pJob, i18n("Reading file: %1", m_pFileAccess->prettyAbsPath()));
return m_bSuccess;
......@@ -1049,7 +1049,7 @@ bool FileAccessJobHandler::put(const void* pSrcBuffer, long maxLength, bool bOve
connect(pJob, &KIO::TransferJob::result, this, &FileAccessJobHandler::slotPutJobResult);
connect(pJob, &KIO::TransferJob::dataReq, this, &FileAccessJobHandler::slotPutData);
connect(pJob, SIGNAL(percent(KJob*, unsigned long)), &pp, SLOT(slotPercent(KJob*, unsigned long)));
connect(pJob, SIGNAL(percent(KJob*, qint64)), &pp, SLOT(slotPercent(KJob*, qint64)));
ProgressProxy::enterEventLoop(pJob, i18n("Writing file: %1", m_pFileAccess->prettyAbsPath()));
return m_bSuccess;
......@@ -1066,10 +1066,15 @@ void FileAccessJobHandler::slotPutData(KIO::Job* pJob, QByteArray& data)
}
else
{
/*
Think twice before doing this in new code.
The maxChunkSize must be able to fit a 32-bit int. Given that the fallowing is safe.
*/
qint64 maxChunkSize = 100000;
qint64 length = min2(maxChunkSize, m_maxLength - m_transferredBytes);
data.resize(length);
if(data.size() == length)
data.resize((int)length);
if(data.size() == (int)length)
{
if(length > 0)
{
......@@ -1190,7 +1195,7 @@ bool FileAccessJobHandler::rename(const QString& dest)
m_bSuccess = false;
KIO::FileCopyJob* pJob = KIO::file_move(m_pFileAccess->url(), kurl, permissions, KIO::HideProgressInfo);
connect(pJob, &KIO::FileCopyJob::result, this, &FileAccessJobHandler::slotSimpleJobResult);
connect(pJob, SIGNAL(percent(KJob*, unsigned long)), &pp, SLOT(slotPercent(KJob*, unsigned long)));
connect(pJob, SIGNAL(percent(KJob*, qint64)), &pp, SLOT(slotPercent(KJob*, qint64)));
ProgressProxy::enterEventLoop(pJob,
i18n("Renaming file: %1 -> %2", m_pFileAccess->prettyAbsPath(), dest));
......@@ -1223,7 +1228,7 @@ bool FileAccessJobHandler::copyFile(const QString& dest)
m_bSuccess = false;
KIO::FileCopyJob* pJob = KIO::file_copy(m_pFileAccess->url(), destUrl, permissions, KIO::HideProgressInfo);
connect(pJob, &KIO::FileCopyJob::result, this, &FileAccessJobHandler::slotSimpleJobResult);
connect(pJob, SIGNAL(percent(KJob*, unsigned long)), &pp, SLOT(slotPercent(KJob*, unsigned long)));
connect(pJob, SIGNAL(percent(KJob*, qint64)), &pp, SLOT(slotPercent(KJob*, qint64)));
ProgressProxy::enterEventLoop(pJob,
i18n("Copying file: %1 -> %2", m_pFileAccess->prettyAbsPath(), dest));
......@@ -1365,7 +1370,7 @@ void CvsIgnoreList::init(FileAccess& dir, bool bUseLocalCvsIgnore)
{
FileAccess file(dir);
file.addPath(".cvsignore");
int size = file.exists() ? file.sizeForReading() : 0;
qint64 size = file.exists() ? file.sizeForReading() : 0;
if(size > 0)
{
char* buf = new char[size];
......@@ -1667,7 +1672,7 @@ bool FileAccessJobHandler::listDir(t_DirectoryList* pDirList, bool bRecursive, b
connect(pListJob, &KIO::ListJob::infoMessage, &pp, &ProgressProxyExtender::slotListDirInfoMessage);
// This line makes the transfer via fish unreliable.:-(
//connect( pListJob, SIGNAL(percent(KJob*,unsigned long)), &pp, SLOT(slotPercent(KJob*, unsigned long)));
//connect( pListJob, SIGNAL(percent(KJob*,qint64)), &pp, SLOT(slotPercent(KJob*, qint64)));
ProgressProxy::enterEventLoop(pListJob,
i18n("Listing directory: %1", m_pFileAccess->prettyAbsPath()));
......@@ -1770,7 +1775,7 @@ void ProgressProxyExtender::slotListDirInfoMessage(KJob*, const QString& msg)
setInformation(msg, 0);
}
void ProgressProxyExtender::slotPercent(KJob*, unsigned long percent)
void ProgressProxyExtender::slotPercent(KJob*, qint64 percent)
{
setCurrent(percent);
}
......
......@@ -33,7 +33,7 @@ public:
ProgressProxyExtender() { setMaxNofSteps(100); }
public Q_SLOTS:
void slotListDirInfoMessage( KJob*, const QString& msg );
void slotPercent( KJob*, unsigned long percent );
void slotPercent( KJob*, qint64 percent );
};
class FileAccess
......@@ -71,8 +71,8 @@ public:
bool isLocal() const;
bool readFile(void* pDestBuffer, unsigned long maxLength );
bool writeFile(const void* pSrcBuffer, unsigned long length );
bool readFile(void* pDestBuffer, qint64 maxLength );
bool writeFile(const void* pSrcBuffer, qint64 length );
bool listDir( t_DirectoryList* pDirList, bool bRecursive, bool bFindHidden,
const QString& filePattern, const QString& fileAntiPattern,
const QString& dirAntiPattern, bool bFollowDirLinks, bool bUseCvsIgnore );
......
......@@ -510,7 +510,7 @@ verify(enough_prime_offsets,
bool GnuDiff::read_files(struct file_data filevec[], bool /*pretend_binary*/)
{
int i;
qint64 i;
find_identical_ends(filevec);
......
......@@ -216,7 +216,7 @@ void ProgressDialog::step(bool bRedrawUpdate)
recalc(bRedrawUpdate);
}
void ProgressDialog::setCurrent(int subCurrent, bool bRedrawUpdate)
void ProgressDialog::setCurrent(qint64 subCurrent, bool bRedrawUpdate)
{
if(m_progressStack.empty())
return;
......@@ -499,7 +499,7 @@ void ProgressProxy::setInformation(const QString& info, int current, bool bRedra
g_pProgressDialog->setInformation(info, current, bRedrawUpdate);
}
void ProgressProxy::setCurrent(int current, bool bRedrawUpdate)
void ProgressProxy::setCurrent(qint64 current, bool bRedrawUpdate)
{
g_pProgressDialog->setCurrent(current, bRedrawUpdate);
}
......
......@@ -30,7 +30,7 @@ public:
void setStayHidden( bool bStayHidden );
void setInformation( const QString& info, bool bRedrawUpdate=true );
void setInformation( const QString& info, int current, bool bRedrawUpdate=true );
void setCurrent( int current, bool bRedrawUpdate=true );
void setCurrent( qint64 current, bool bRedrawUpdate=true );
void step( bool bRedrawUpdate=true );
void setMaxNofSteps(const qint64 dMaxNofSteps );
void addNofSteps(const qint64 nofSteps );
......@@ -118,7 +118,7 @@ public:
void setInformation( const QString& info, bool bRedrawUpdate=true );
void setInformation( const QString& info, int current, bool bRedrawUpdate=true );
void setCurrent( int current, bool bRedrawUpdate=true );
void setCurrent( qint64 current, bool bRedrawUpdate=true );
void step( bool bRedrawUpdate=true );
void setMaxNofSteps( const qint64 maxNofSteps );
void addNofSteps( const qint64 nofSteps );
......
......@@ -40,7 +40,7 @@ void ProgressProxy::setInformation( const QString& info, int current, bool bRedr
(void)bRedrawUpdate;
}
void ProgressProxy::setCurrent( int current, bool bRedrawUpdate )
void ProgressProxy::setCurrent( qint64 current, bool bRedrawUpdate )
{
/* Suppress warning about unused parameters */
(void)current;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment