Skip to content

Commit

Permalink
[#57] Support for KryoFlux and associated images (Part 192: Fixed buf…
Browse files Browse the repository at this point in the history
…fer overrun in track normalization)
  • Loading branch information
tomas-nestorovic committed Feb 19, 2024
1 parent f4470b3 commit 65a8992
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Main/src/Image.h
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@
void RemoveConsecutiveBeforeEnd(TLogTime tEndMax);
};
protected:
const PLogTime logTimes; // absolute logical times since the start of recording
PLogTime logTimes; // absolute logical times since the start of recording
const TDecoderMethod method;
bool resetDecoderOnIndex;
DWORD iNextTime,nLogTimes;
Expand Down
25 changes: 14 additions & 11 deletions Main/src/Image_TrackRW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1525,10 +1525,11 @@
// - ignoring what's before the first Index
TLogTime tCurrIndexOrg=RewindToIndex(0);
// - normalization
const TLogTime tLastIndex=GetIndexTime(nIndexPulses-1);
const TLogTime tLastIndex=GetLastIndexTime();
const DWORD iModifStart=iNextTime;
DWORD iTime=iModifStart;
const Utils::CCallocPtr<TLogTime> buffer(GetBufferCapacity());
const DWORD nLogTimesMaxNew=std::max( nIndexPulses*mp->nCells, GetBufferCapacity() );
const Utils::CCallocPtr<TLogTime> buffer( nLogTimesMaxNew, 0 ); // pessimistic estimation for FM encoding
const PLogTime ptModified=buffer.get();
for( BYTE nextIndex=1; nextIndex<nIndexPulses; nextIndex++ ){
// . resetting inspection conditions
Expand All @@ -1541,7 +1542,7 @@
// alignment wanted
for( ; *this&&logTimes[iNextTime]<tNextIndexOrg; nAlignedCells++ )
if (ReadBit())
if (iTime<GetBufferCapacity())
if (iTime<nLogTimesMaxNew)
ptModified[iTime++] = tCurrIndexOrg + nAlignedCells*profile.iwTimeDefault;
else
return ERROR_INSUFFICIENT_BUFFER; // mustn't overrun the Buffer
Expand Down Expand Up @@ -1597,15 +1598,17 @@
iTime=iModifRevEnd;
}
// - copying Modified LogicalTimes to the Track
if (nLogTimes+iTime-iNextTime>=GetBufferCapacity())
return ERROR_INSUFFICIENT_BUFFER; // mustn't overrun the Buffer
::memmove( logTimes+iTime, logTimes+iNextTime, (nLogTimes-iNextTime)*sizeof(TLogTime) );
nLogTimes+=iTime-iNextTime;
if (const TLogTime dt=indexPulses[nIndexPulses-1]-tLastIndex)
for( DWORD i=iTime; i<nLogTimes; logTimes[i++]+=dt );
::memcpy( logTimes+iModifStart, ptModified+iModifStart, (iTime-iModifStart)*sizeof(TLogTime) );
const DWORD nNewLogTimes=nLogTimes+iTime-iNextTime;
CTrackReaderWriter tmp( nLogTimesMaxNew, method, resetDecoderOnIndex );
::memcpy( tmp.logTimes, logTimes, iModifStart*sizeof(TLogTime) ); // Times before first Index
::memcpy( tmp.logTimes+iModifStart, ptModified+iModifStart, (iTime-iModifStart)*sizeof(TLogTime) ); // Times in full Revolutions
::memcpy( tmp.logTimes+iTime, logTimes+iNextTime, (nLogTimes-iNextTime)*sizeof(TLogTime) ); // Times after last Index
if (const TLogTime dt=GetLastIndexTime()-tLastIndex)
for( DWORD i=iTime; i<nNewLogTimes; tmp.logTimes[i++]+=dt );
std::swap( tmp.logTimes, logTimes );
nLogTimes=nNewLogTimes;
SetCurrentTime(0); // setting valid state
// - successfully aligned
// - successfully normalized
return ERROR_SUCCESS;
}

Expand Down
2 changes: 1 addition & 1 deletion Main/src/stdafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ struct TLogTimeInterval{

#define APP_FULLNAME _T("Real and Imaginary Disk Editor")
#define APP_ABBREVIATION "RIDE"
#define APP_VERSION "1.7.5 debug special"
#define APP_VERSION "1.7.5.1"
//#define APP_SPECIAL_VER
#define APP_IDENTIFIER APP_ABBREVIATION APP_VERSION
#define APP_CLASSNAME _T("Afx:tomascz.") _T(APP_ABBREVIATION)
Expand Down

0 comments on commit 65a8992

Please sign in to comment.