Commit 34abefce authored by Michael Reeves's avatar Michael Reeves

Fix type for line counts/numbers to always use LineRef

Begin convertion of int to LineRef.
parent 49d972d9
......@@ -280,7 +280,7 @@ const LineData* SourceData::getLineDataForDisplay() const
return m_normalData.m_v.size() > 0 ? &m_normalData.m_v[0] : nullptr;
}
int SourceData::getSizeLines() const
LineRef SourceData::getSizeLines() const
{
return m_normalData.m_vSize;
}
......@@ -795,13 +795,16 @@ QStringList SourceData::readAndPreprocess(QTextCodec* pEncoding, bool bAutoDetec
}
else
{
//FIXME: Remove this hack after determining root cause.
if(m_lmppData.m_vSize < m_normalData.m_vSize)
{
//This a bug that needs fixed elsewhere not hacked around
Q_ASSERT(m_lmppData.m_vSize == m_normalData.m_vSize);
// This probably is the fault of the LMPP-Command, but not worth reporting.
m_lmppData.m_v.resize(m_normalData.m_vSize);
for(int i = m_lmppData.m_vSize; i < m_normalData.m_vSize; ++i)
m_lmppData.m_v.resize((int)m_normalData.m_vSize);
for(qint64 i = m_lmppData.m_vSize; i < m_normalData.m_vSize; ++i)
{ // Set all empty lines to point to the end of the buffer.
m_lmppData.m_v[i].pLine = m_lmppData.m_unicodeBuf.unicode() + m_lmppData.m_unicodeBuf.length();
m_lmppData.m_v[(int)i].pLine = m_lmppData.m_unicodeBuf.unicode() + m_lmppData.m_unicodeBuf.length();
}
m_lmppData.m_vSize = m_normalData.m_vSize;
......@@ -823,10 +826,10 @@ QStringList SourceData::readAndPreprocess(QTextCodec* pEncoding, bool bAutoDetec
if(m_pOptions->m_bIgnoreComments)
{
m_lmppData.removeComments();
int vSize = min2(m_normalData.m_vSize, m_lmppData.m_vSize);
for(int i = 0; i < vSize; ++i)
LineRef vSize = min2(m_normalData.m_vSize, m_lmppData.m_vSize);
for(LineRef i = 0; i < vSize; ++i)
{
m_normalData.m_v[i].bContainsPureComment = m_lmppData.m_v[i].bContainsPureComment;
m_normalData.m_v[(int)i].bContainsPureComment = m_lmppData.m_v[(int)i].bContainsPureComment;
}
}
}
......@@ -1546,7 +1549,7 @@ static bool isValidMove(ManualDiffHelpList* pManualDiffHelpList, int line1, int
return true; // no barrier passed.
}
static bool runDiff(const LineData* p1, int size1, const LineData* p2, int size2, DiffList& diffList,
static bool runDiff(const LineData* p1, LineRef size1, const LineData* p2, LineRef size2, DiffList& diffList,
Options* pOptions)
{
ProgressProxy pp;
......@@ -1585,9 +1588,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);
lin equalLinesAtStart = comparisonInput.file[0].prefix_lines;
lin currentLine1 = 0;
lin currentLine2 = 0;
LineRef equalLinesAtStart = comparisonInput.file[0].prefix_lines;
LineRef currentLine1 = 0;
LineRef currentLine2 = 0;
GnuDiff::change* p = nullptr;
for(GnuDiff::change* e = script; e; e = p)
{
......@@ -1632,7 +1635,7 @@ static bool runDiff(const LineData* p1, int size1, const LineData* p2, int size2
currentLine1 += equalLinesAtStart;
currentLine2 += equalLinesAtStart;
lin nofEquals = min2(size1 - currentLine1, size2 - currentLine2);
LineRef nofEquals = min2(size1 - currentLine1, size2 - currentLine2);
if(nofEquals == 0)
{
diffList.back().diff1 += size1 - currentLine1;
......@@ -1660,8 +1663,8 @@ static bool runDiff(const LineData* p1, int size1, const LineData* p2, int size2
// Verify difflist
{
lin l1 = 0;
lin l2 = 0;
LineRef l1 = 0;
LineRef l2 = 0;
DiffList::iterator i;
for(i = diffList.begin(); i != diffList.end(); ++i)
{
......@@ -1678,7 +1681,7 @@ static bool runDiff(const LineData* p1, int size1, const LineData* p2, int size2
return true;
}
bool runDiff(const LineData* p1, int size1, const LineData* p2, int size2, DiffList& diffList,
bool runDiff(const LineData* p1, LineRef size1, const LineData* p2, LineRef size2, DiffList& diffList,
int winIdx1, int winIdx2,
ManualDiffHelpList* pManualDiffHelpList,
Options* pOptions)
......@@ -2166,7 +2169,7 @@ void calcDiff3LineListTrim(
}
void DiffBufferInfo::init(Diff3LineList* pD3ll, const Diff3LineVector* pD3lv,
const LineData* pldA, int sizeA, const LineData* pldB, int sizeB, const LineData* pldC, int sizeC)
const LineData* pldA, LineRef sizeA, const LineData* pldB, LineRef sizeB, const LineData* pldC, LineRef sizeC)
{
m_pDiff3LineList = pD3ll;
m_pDiff3LineVector = pD3lv;
......@@ -2208,7 +2211,7 @@ inline bool equal(QChar c1, QChar c2, bool /*bStrict*/)
// My own diff-invention:
template <class T>
void calcDiff(const T* p1, int size1, const T* p2, int size2, DiffList& diffList, int match, int maxSearchRange)
void calcDiff(const T* p1, LineRef size1, const T* p2, LineRef size2, DiffList& diffList, int match, int maxSearchRange)
{
diffList.clear();
......@@ -2350,8 +2353,8 @@ void calcDiff(const T* p1, int size1, const T* p2, int size2, DiffList& diffList
// Verify difflist
{
int l1 = 0;
int l2 = 0;
LineRef l1 = 0;
LineRef l2 = 0;
DiffList::iterator i;
for(i = diffList.begin(); i != diffList.end(); ++i)
{
......@@ -2373,8 +2376,8 @@ bool fineDiff(
ProgressProxy pp;
int maxSearchLength = 500;
Diff3LineList::iterator i;
int k1 = 0;
int k2 = 0;
LineRef k1 = 0;
LineRef k2 = 0;
bool bTextsTotalEqual = true;
int listSize = diff3LineList.size();
pp.setMaxNofSteps(listSize);
......
......@@ -31,12 +31,12 @@
// Then again range of matching elements should follow.
struct Diff
{
lin nofEquals;
LineRef nofEquals;
qint64 diff1;
qint64 diff2;
Diff(lin eq, qint64 d1, qint64 d2){nofEquals=eq; diff1=d1; diff2=d2; }
Diff(LineRef eq, qint64 d1, qint64 d2){nofEquals=eq; diff1=d1; diff2=d2; }
};
typedef std::list<Diff> DiffList;
......@@ -63,20 +63,20 @@ struct DiffBufferInfo
const LineData* m_pLineDataA;
const LineData* m_pLineDataB;
const LineData* m_pLineDataC;
int m_sizeA;
int m_sizeB;
int m_sizeC;
LineRef m_sizeA;
LineRef m_sizeB;
LineRef m_sizeC;
const Diff3LineList* m_pDiff3LineList;
const Diff3LineVector* m_pDiff3LineVector;
void init( Diff3LineList* d3ll, const Diff3LineVector* d3lv,
const LineData* pldA, int sizeA, const LineData* pldB, int sizeB, const LineData* pldC, int sizeC );
const LineData* pldA, LineRef sizeA, const LineData* pldB, LineRef sizeB, const LineData* pldC, LineRef sizeC );
};
struct Diff3Line
{
int lineA;
int lineB;
int lineC;
LineRef lineA;
LineRef lineB;
LineRef lineC;
bool bAEqC : 1; // These are true if equal or only white-space changes exist.
bool bBEqC : 1;
......@@ -136,7 +136,7 @@ struct Diff3Line
else
return QString();
}
int getLineInFile( int src ) const
LineRef getLineInFile( int src ) const
{
if ( src == 1 ) return lineA;
if ( src == 2 ) return lineB;
......@@ -194,21 +194,21 @@ public:
ManualDiffHelpEntry() { lineA1=-1; lineA2=-1;
lineB1=-1; lineB2=-1;
lineC1=-1; lineC2=-1; }
int lineA1;
int lineA2;
int lineB1;
int lineB2;
int lineC1;
int lineC2;
int& firstLine( int winIdx )
LineRef lineA1;
LineRef lineA2;
LineRef lineB1;
LineRef lineB2;
LineRef lineC1;
LineRef lineC2;
LineRef& firstLine( int winIdx )
{
return winIdx==1 ? lineA1 : (winIdx==2 ? lineB1 : lineC1 );
}
int& lastLine( int winIdx )
LineRef& lastLine( int winIdx )
{
return winIdx==1 ? lineA2 : (winIdx==2 ? lineB2 : lineC2 );
}
bool isLineInRange( int line, int winIdx )
bool isLineInRange( LineRef line, int winIdx )
{
return line>=0 && line>=firstLine(winIdx) && line<=lastLine(winIdx);
}
......@@ -247,7 +247,7 @@ public:
void setOptions( Options* pOptions );
int getSizeLines() const;
LineRef getSizeLines() const;
qint64 getSizeBytes() const;
const char* getBuf() const;
const QString& getText() const;
......@@ -293,7 +293,7 @@ private:
~FileData(){ reset(); }
const char* m_pBuf;
qint64 m_size;
int m_vSize; // Nr of lines in m_pBuf1 and size of m_v1, m_dv12 and m_dv13
qint64 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;
bool m_bIsText;
......@@ -332,20 +332,20 @@ class Selection
public:
Selection(){}
private:
int firstLine = -1;
int lastLine = -1;
LineRef firstLine = -1;
LineRef lastLine = -1;
int firstPos = -1;
int lastPos = -1;
int oldFirstLine = -1;
int oldLastLine = -1;
LineRef oldFirstLine = -1;
LineRef oldLastLine = -1;
public:
//private:
bool bSelectionContainsData = false;
public:
inline int getFirstLine() { return firstLine; };
inline int getLastLine() { return lastLine; };
inline LineRef getFirstLine() { return firstLine; };
inline LineRef getLastLine() { return lastLine; };
inline int getFirstPos() { return firstPos; };
inline int getLastPos() { return lastPos; };
......@@ -353,8 +353,8 @@ public:
inline bool isValidFirstLine() { return firstLine != -1; }
inline void clearOldSelection() { oldLastLine = -1, oldFirstLine = -1; };
inline int getOldLastLine() { return oldLastLine; };
inline int getOldFirstLine() { return oldFirstLine; };
inline LineRef getOldLastLine() { return oldLastLine; };
inline LineRef getOldFirstLine() { return oldFirstLine; };
inline bool selectionContainsData(void) { return bSelectionContainsData; };
bool isEmpty() { return firstLine == -1 || (firstLine == lastLine && firstPos == lastPos) || bSelectionContainsData == false; }
void reset()
......@@ -365,24 +365,24 @@ public:
lastLine = -1;
bSelectionContainsData = false;
}
void start( int l, int p ) { firstLine = l; firstPos = p; }
void end( int l, int p ) {
void start( LineRef l, int p ) { firstLine = l; firstPos = p; }
void end( LineRef l, int p ) {
if ( oldLastLine == -1 )
oldLastLine = lastLine;
lastLine = l;
lastPos = p;
//bSelectionContainsData = (firstLine == lastLine && firstPos == lastPos);
}
bool within( int l, int p );
bool within( LineRef l, LineRef p );
bool lineWithin( int l );
int firstPosInLine(int l);
int lastPosInLine(int l);
int beginLine(){
bool lineWithin( LineRef l );
int firstPosInLine(LineRef l);
int lastPosInLine(LineRef l);
LineRef beginLine(){
if (firstLine<0 && lastLine<0) return -1;
return max2(0,min2(firstLine,lastLine));
return max2((LineRef)0,min2(firstLine,lastLine));
}
int endLine(){
LineRef endLine(){
if (firstLine<0 && lastLine<0) return -1;
return max2(firstLine,lastLine);
}
......@@ -448,7 +448,7 @@ public:
}
};
bool runDiff( const LineData* p1, int size1, const LineData* p2, int size2, DiffList& diffList, int winIdx1, int winIdx2,
bool runDiff( const LineData* p1, LineRef size1, const LineData* p2, LineRef size2, DiffList& diffList, int winIdx1, int winIdx2,
ManualDiffHelpList *pManualDiffHelpList, Options *pOptions);
bool fineDiff(
......
This diff is collapsed.
......@@ -46,34 +46,34 @@ public:
QTextCodec* pCodec,
e_LineEndStyle eLineEndStyle,
const LineData* pLineData,
int size,
LineRef size,
const Diff3LineVector* pDiff3LineVector,
const ManualDiffHelpList* pManualDiffHelpList,
bool bTriple
);
void reset();
void convertToLinePos( int x, int y, int& line, int& pos );
void convertToLinePos( int x, int y, LineRef& line, int& pos );
QString getSelection();
int getFirstLine();
int calcTopLineInFile( int firstLine );
LineRef calcTopLineInFile( int firstLine );
int getMaxTextWidth();
int getNofLines();
int getNofVisibleLines();
int getVisibleTextAreaWidth();
int convertLineToDiff3LineIdx( int line );
int convertDiff3LineIdxToLine( int d3lIdx );
LineRef convertLineToDiff3LineIdx( LineRef line );
LineRef convertDiff3LineIdxToLine( LineRef d3lIdx );
void convertD3LCoordsToLineCoords( int d3LIdx, int d3LPos, int& line, int& pos );
void convertLineCoordsToD3LCoords( int line, int pos, int& d3LIdx, int& d3LPos );
void convertD3LCoordsToLineCoords( LineRef d3LIdx, int d3LPos, LineRef& line, int& pos );
void convertLineCoordsToD3LCoords( LineRef line, int pos, LineRef& d3LIdx, int& d3LPos );
void convertSelectionToD3LCoords();
bool findString( const QString& s, int& d3vLine, int& posInLine, bool bDirDown, bool bCaseSensitive );
void setSelection( int firstLine, int startPos, int lastLine, int endPos, int& l, int& p );
void getSelectionRange( int* firstLine, int* lastLine, e_CoordType coordType );
void setSelection( LineRef firstLine, int startPos, LineRef lastLine, int endPos, LineRef& l, int& p );
void getSelectionRange( LineRef* firstLine, LineRef* lastLine, e_CoordType coordType );
void setPaintingAllowed( bool bAllowPainting );
void recalcWordWrap( bool bWordWrap, int wrapLineVectorSize, int nofVisibleColumns);
......@@ -86,13 +86,13 @@ Q_SIGNALS:
void selectionEnd();
void setFastSelectorLine( int line );
void gotFocus();
void lineClicked( int winIdx, int line );
void lineClicked( int winIdx, LineRef line );
public Q_SLOTS:
void setFirstLine( int line );
void setFirstLine( LineRef line );
void setHorizScrollOffset( int horizScrollOffset );
void resetSelection();
void setFastSelectorRange( int line1, int nofLines );
void setFastSelectorRange( LineRef line1, LineRef nofLines );
protected:
void mousePressEvent ( QMouseEvent * ) override;
......
This diff is collapsed.
......@@ -62,7 +62,7 @@ bool no_diff_means_no_output;
/* Number of lines of context to show in each set of diffs.
This is zero when context is not to be shown. */
lin context;
LineRef context;
/* Consider all files as text files (-a).
Don't interpret codes over 0177 as implying a "binary file". */
......@@ -172,10 +172,10 @@ bool minimal;
struct change
{
struct change *link; /* Previous or next edit command */
lin inserted; /* # lines of file 1 changed here. */
lin deleted; /* # lines of file 0 changed here. */
lin line0; /* Line number of 1st deleted line. */
lin line1; /* Line number of 1st inserted line. */
LineRef inserted; /* # lines of file 1 changed here. */
LineRef deleted; /* # lines of file 0 changed here. */
LineRef line0; /* Line number of 1st deleted line. */
LineRef line1; /* Line number of 1st inserted line. */
bool ignore; /* Flag used in context.c. */
};
......@@ -201,14 +201,14 @@ struct file_data {
linebuf[linbuf_base ... buffered_lines - 1] are possibly differing.
linebuf[linbuf_base ... valid_lines - 1] contain valid data.
linebuf[linbuf_base ... alloc_lines - 1] are allocated. */
lin linbuf_base, buffered_lines, valid_lines, alloc_lines;
LineRef linbuf_base, buffered_lines, valid_lines, alloc_lines;
/* Pointer to end of prefix of this file to ignore when hashing. */
const QChar *prefix_end;
/* Count of lines in the prefix.
There are this many lines in the file before linbuf[0]. */
lin prefix_lines;
LineRef prefix_lines;
/* Pointer to start of suffix of this file to ignore when hashing. */
const QChar *suffix_begin;
......@@ -216,18 +216,18 @@ struct file_data {
/* Vector, indexed by line number, containing an equivalence code for
each line. It is this vector that is actually compared with that
of another file to generate differences. */
lin *equivs;
LineRef *equivs;
/* Vector, like the previous one except that
the elements for discarded lines have been squeezed out. */
lin *undiscarded;
LineRef *undiscarded;
/* Vector mapping virtual line numbers (not counting discarded lines)
to real ones (counting those lines). Both are origin-0. */
lin *realindexes;
LineRef *realindexes;
/* Total number of nondiscarded lines. */
lin nondiscarded_lines;
LineRef nondiscarded_lines;
/* Vector, indexed by real origin-0 line number,
containing TRUE for a line that is an insertion or a deletion.
......@@ -239,7 +239,7 @@ struct file_data {
/* 1 more than the maximum equivalence value used for this or its
sibling file. */
lin equiv_max;
LineRef equiv_max;
};
/* Data on two input files being compared. */
......@@ -293,11 +293,11 @@ void print_sdiff_script (struct change *);
/* util.c */
QChar *concat (const QChar *, const QChar *, const QChar *);
bool lines_differ ( const QChar *, size_t, const QChar *, size_t );
lin translate_line_number (struct file_data const *, lin);
LineRef translate_line_number (struct file_data const *, LineRef);
struct change *find_change (struct change *);
struct change *find_reverse_change (struct change *);
void *zalloc (size_t);
enum changes analyze_hunk (struct change *, lin *, lin *, lin *, lin *);
enum changes analyze_hunk (struct change *, LineRef *, LineRef *, LineRef *, LineRef *);
void begin_output (void);
void debug_script (struct change *);
void finish_output (void);
......@@ -306,18 +306,18 @@ void message5 (const QChar *, const QChar *, const QChar *, const QChar *, const
void output_1_line (const QChar *, const QChar *, const QChar *, const QChar *);
void perror_with_name (const QChar *);
void setup_output (const QChar *, const QChar *, bool);
void translate_range (struct file_data const *, lin, lin, long *, long *);
void translate_range (struct file_data const *, LineRef, LineRef, long *, long *);
/* version.c */
//extern const QChar version_string[];
private:
// gnudiff_analyze.cpp
lin diag (lin xoff, lin xlim, lin yoff, lin ylim, bool find_minimal, struct partition *part);
void compareseq (lin xoff, lin xlim, lin yoff, lin ylim, bool find_minimal);
LineRef diag (LineRef xoff, LineRef xlim, LineRef yoff, LineRef ylim, bool find_minimal, struct partition *part);
void compareseq (LineRef xoff, LineRef xlim, LineRef yoff, LineRef ylim, bool find_minimal);
void discard_confusing_lines (struct file_data filevec[]);
void shift_boundaries (struct file_data filevec[]);
struct change * add_change (lin line0, lin line1, lin deleted, lin inserted, struct change *old);
struct change * add_change (LineRef line0, LineRef line1, LineRef deleted, LineRef inserted, struct change *old);
struct change * build_reverse_script (struct file_data const filevec[]);
struct change* build_script (struct file_data const filevec[]);
......
......@@ -39,7 +39,7 @@ verify(hash_value_is_unsigned, !TYPE_SIGNED(hash_value));
but only while the classes are being computed.
Afterward, each class is represented by a number. */
struct equivclass {
lin next; /* Next item in this bucket. */
LineRef next; /* Next item in this bucket. */
hash_value hash; /* Hash of lines in this class. */
const QChar *line; /* A line that fits this class. */
size_t length; /* That line's length, not counting its newline. */
......@@ -47,7 +47,7 @@ struct equivclass {
/* Hash-table: array of buckets, each being a chain of equivalence classes.
buckets[-1] is reserved for incomplete lines. */
static lin *buckets;
static LineRef *buckets;
/* Number of buckets in the hash table array, not counting buckets[-1]. */
static size_t nbuckets;
......@@ -58,10 +58,10 @@ static size_t nbuckets;
static struct equivclass *equivs;
/* Index of first free element in the array `equivs'. */
static lin equivs_index;
static LineRef equivs_index;
/* Number of elements allocated in the array `equivs'. */
static lin equivs_alloc;
static LineRef equivs_alloc;
/* Check for binary files and compare them for exact identity. */
......@@ -133,18 +133,18 @@ void GnuDiff::find_and_hash_each_line(struct file_data *current)
hash_value h;
const QChar *p = current->prefix_end;
QChar c;
lin i, *bucket;
LineRef i, *bucket;
size_t length;
/* Cache often-used quantities in local variables to help the compiler. */
const QChar **linbuf = current->linbuf;
lin alloc_lines = current->alloc_lines;
lin line = 0;
lin linbuf_base = current->linbuf_base;
lin *cureqs = (lin *)xmalloc(alloc_lines * sizeof *cureqs);
LineRef alloc_lines = current->alloc_lines;
LineRef line = 0;
LineRef linbuf_base = current->linbuf_base;
LineRef *cureqs = (LineRef *)xmalloc(alloc_lines * sizeof *cureqs);
struct equivclass *eqs = equivs;
lin eqs_index = equivs_index;
lin eqs_alloc = equivs_alloc;
LineRef eqs_index = equivs_index;
LineRef eqs_alloc = equivs_alloc;
const QChar *suffix_begin = current->suffix_begin;
const QChar *bufend = current->buffer + current->buffered;
bool diff_length_compare_anyway =
......@@ -211,7 +211,7 @@ void GnuDiff::find_and_hash_each_line(struct file_data *current)
i = eqs_index++;
if(i == eqs_alloc)
{
if((lin)(PTRDIFF_MAX / (2 * sizeof *eqs)) <= eqs_alloc)
if((LineRef)(PTRDIFF_MAX / (2 * sizeof *eqs)) <= eqs_alloc)
xalloc_die();
eqs_alloc *= 2;
eqs = (equivclass *)xrealloc(eqs, eqs_alloc * sizeof *eqs);
......@@ -250,10 +250,10 @@ void GnuDiff::find_and_hash_each_line(struct file_data *current)
if(line == alloc_lines)
{
/* Double (alloc_lines - linbuf_base) by adding to alloc_lines. */
if((lin)(PTRDIFF_MAX / 3) <= alloc_lines || (lin)(PTRDIFF_MAX / sizeof *cureqs) <= 2 * alloc_lines - linbuf_base || (lin)(PTRDIFF_MAX / sizeof *linbuf) <= alloc_lines - linbuf_base)
if((LineRef)(PTRDIFF_MAX / 3) <= alloc_lines || (LineRef)(PTRDIFF_MAX / sizeof *cureqs) <= 2 * alloc_lines - linbuf_base || (LineRef)(PTRDIFF_MAX / sizeof *linbuf) <= alloc_lines - linbuf_base)
xalloc_die();
alloc_lines = 2 * alloc_lines - linbuf_base;
cureqs = (lin *)xrealloc(cureqs, alloc_lines * sizeof *cureqs);
cureqs = (LineRef *)xrealloc(cureqs, alloc_lines * sizeof *cureqs);
linbuf += linbuf_base;
linbuf = (const QChar **)xrealloc(linbuf,
(alloc_lines - linbuf_base) * sizeof *linbuf);
......@@ -274,7 +274,7 @@ void GnuDiff::find_and_hash_each_line(struct file_data *current)
if(line == alloc_lines)
{
/* Double (alloc_lines - linbuf_base) by adding to alloc_lines. */
if((lin)(PTRDIFF_MAX / 3) <= alloc_lines || (lin)(PTRDIFF_MAX / sizeof *cureqs) <= 2 * alloc_lines - linbuf_base || (lin)(PTRDIFF_MAX / sizeof *linbuf) <= alloc_lines - linbuf_base)
if((LineRef)(PTRDIFF_MAX / 3) <= alloc_lines || (LineRef)(PTRDIFF_MAX / sizeof *cureqs) <= 2 * alloc_lines - linbuf_base || (LineRef)(PTRDIFF_MAX / sizeof *linbuf) <= alloc_lines - linbuf_base)
xalloc_die();
alloc_lines = 2 * alloc_lines - linbuf_base;
linbuf += linbuf_base;
......@@ -310,12 +310,12 @@ void GnuDiff::find_and_hash_each_line(struct file_data *current)
proportionate number of lines that will be found in a buffer of
size T. However, do not guess a number of lines so large that the
resulting line table might cause overflow in size calculations. */
static lin
guess_lines(lin n, size_t s, size_t t)
static LineRef
guess_lines(LineRef n, size_t s, size_t t)
{
size_t guessed_bytes_per_line = n < 10 ? 32 : s / (n - 1);
lin guessed_lines = MAX(1, t / guessed_bytes_per_line);
return MIN(guessed_lines, (lin)(PTRDIFF_MAX / (2 * sizeof(QChar *) + 1) - 5)) + 5;
LineRef guessed_lines = MAX((LineRef)1, t / guessed_bytes_per_line);
return MIN(guessed_lines, (LineRef)(LIN_MAX / (2 * sizeof(QChar *) + 1) - 5)) + 5;
}
/* Given a vector of two file_data objects, find the identical
......@@ -411,10 +411,10 @@ void GnuDiff::find_identical_ends(struct file_data filevec[])
rounded up to the next power of 2 to speed index computation. */
const QChar **linbuf0, **linbuf1;
lin alloc_lines0, alloc_lines1;
lin buffered_prefix, prefix_count, prefix_mask;
lin middle_guess, suffix_guess;
if(no_diff_means_no_output && context < (lin)(LIN_MAX / 4) && context < (lin)(n0))
LineRef alloc_lines0, alloc_lines1;
LineRef buffered_prefix, prefix_count, prefix_mask;
LineRef middle_guess, suffix_guess;
if(no_diff_means_no_output && context < (LineRef)(LIN_MAX / 4) && context < (LineRef)(n0))
{
middle_guess = guess_lines(0, 0, p0 - filevec[0].prefix_end);
suffix_guess = guess_lines(0, 0, buffer0 + n0 - p0);
......@@ -429,7 +429,7 @@ void GnuDiff::find_identical_ends(struct file_data filevec[])
}
prefix_mask = prefix_count - 1;
lin lines = 0;
LineRef lines = 0;
linbuf0 = (const QChar **)xmalloc(alloc_lines0 * sizeof(*linbuf0));
p0 = buffer0;
......@@ -439,10 +439,10 @@ void GnuDiff::find_identical_ends(struct file_data filevec[])
end0 = filevec[0].prefix_end;
while(p0 != end0)
{
lin l = lines++ & prefix_mask;
LineRef l = lines++ & prefix_mask;
if(l == alloc_lines0)
{
if((lin)(PTRDIFF_MAX / (2 * sizeof *linbuf0)) <= alloc_lines0)
if((LineRef)(PTRDIFF_MAX / (2 * sizeof *linbuf0)) <= alloc_lines0)
xalloc_die();
alloc_lines0 *= 2;
linbuf0 = (const QChar **)xrealloc(linbuf0, alloc_lines0 * sizeof(*linbuf0));
......@@ -459,11 +459,11 @@ void GnuDiff::find_identical_ends(struct file_data filevec[])
middle_guess = guess_lines(lines, p0 - buffer0, p1 - filevec[1].prefix_end);
suffix_guess = guess_lines(lines, p0 - buffer0, buffer1 + n1 - p1);
alloc_lines1 = buffered_prefix + middle_guess + MIN(context, suffix_guess);
if(alloc_lines1 < buffered_prefix || (lin)(PTRDIFF_MAX / sizeof *linbuf1) <= alloc_lines1)
if(alloc_lines1 < buffered_prefix || (LineRef)(PTRDIFF_MAX / sizeof *linbuf1) <= alloc_lines1)
xalloc_die();
linbuf1 = (const QChar **)xmalloc(alloc_lines1 * sizeof(*linbuf1));
lin i;
LineRef i;
if(buffered_prefix != lines)
{
/* Rotate prefix lines to proper location. */
......@@ -510,12 +510,12 @@ verify(enough_prime_offsets,
bool GnuDiff::read_files(struct file_data filevec[], bool /*pretend_binary*/)
{
size_t i;
LineRef i;
find_identical_ends(filevec);
equivs_alloc = filevec[0].alloc_lines + filevec[1].alloc_lines + 1;
if((lin)(PTRDIFF_MAX / sizeof *equivs) <= equivs_alloc)
if((LineRef)(PTRDIFF_MAX / sizeof *equivs) <= equivs_alloc)
xalloc_die();
equivs = (equivclass *)xmalloc(equivs_alloc * sizeof *equivs);
/* Equivalence class 0 is permanently safe for lines that were not
......@@ -525,12 +525,12 @@ bool GnuDiff::read_files(struct file_data filevec[], bool /*pretend_binary*/)
/* Allocate (one plus) a prime number of hash buckets. Use a prime
number between 1/3 and 2/3 of the value of equiv_allocs,
approximately. */
for(i = 9; ((size_t)1 << i) < equivs_alloc / 3; i++)
for(i = 9; ((LineRef)1 << i) < equivs_alloc / 3; i++)
continue;
nbuckets = ((size_t)1 << i) - prime_offset[i];
nbuckets = ((LineRef)1 << i) - prime_offset[i];
if(PTRDIFF_MAX / sizeof *buckets <= nbuckets)
xalloc_die();
buckets = (lin *)zalloc((nbuckets + 1) * sizeof *buckets);
buckets = (LineRef *)zalloc((nbuckets + 1) * sizeof *buckets);
buckets++;
for(i = 0; i < 2; i++)
......
......@@ -24,6 +24,8 @@
#ifndef GNUDIFF_SYSTEM_H