1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-05-04 17:49:45 +02:00

(bug 451, P2)

Changes per Martyn's suggestion (http://bugzilla.audacityteam.org/show_bug.cgi?id=451#c24), i.e., deal with sample format mismatch in WaveClip::Paste() and Sequence::Paste().

Also add error checking for bad s parameter values passed to Sequence::Paste().
This commit is contained in:
v.audacity 2011-11-20 03:46:00 +00:00
parent 41ed3aaae8
commit 8cc8a275f8
2 changed files with 42 additions and 6 deletions

View File

@ -386,14 +386,41 @@ bool Sequence::Copy(sampleCount s0, sampleCount s1, Sequence **dest)
bool Sequence::Paste(sampleCount s, const Sequence *src)
{
if (s < 0)
s = 0;
if (s >= mNumSamples)
s = mNumSamples;
// This ancient code just blithely bounded s, rather than throwing an error.
// Now enforcing the bounds.
//if ((s < 0)
// s = 0;
//if (s >= mNumSamples)
// s = mNumSamples;
if ((s < 0) || (s >= mNumSamples))
{
wxLogError(
wxT("Sequence::Paste: sampleCount s %s is < 0 or > mNumSamples %s)."),
Internat::ToString(((wxLongLong)s).ToDouble(), 0).c_str(),
Internat::ToString(((wxLongLong)mNumSamples).ToDouble(), 0).c_str());
wxASSERT(false);
return false;
}
// Quick check to make sure that it doesn't overflow
if (((double)mNumSamples) + ((double)src->mNumSamples) > wxLL(9223372036854775807))
{
wxLogError(
wxT("Sequence::Paste: mNumSamples %s + src->mNumSamples %s would overflow."),
Internat::ToString(((wxLongLong)mNumSamples).ToDouble(), 0).c_str(),
Internat::ToString(((wxLongLong)src->mNumSamples).ToDouble(), 0).c_str());
wxASSERT(false);
return false;
}
if (src->mSampleFormat != mSampleFormat)
{
wxLogError(
wxT("Sequence::Paste: Sample format to be pasted, %s, does not match destination format, %s."),
GetSampleFormatStr(src->mSampleFormat), GetSampleFormatStr(src->mSampleFormat));
wxASSERT(false);
return false;
}
BlockArray *srcBlock = src->mBlock;
sampleCount addedLen = src->mNumSamples;

View File

@ -1241,8 +1241,17 @@ bool WaveClip::Paste(double t0, WaveClip* other)
sampleCount s0;
TimeToSamplesClip(t0, &s0);
bool result = false;
// Check whether sample formats match.
if (pastedClip->mSequence->GetSampleFormat() != mSequence->GetSampleFormat())
{
// In debug mode, fail because that's probably a bad call to this method.
// In release, adjust the source to match the destination, so we don't do a bad paste.
// Conversion probably should have been done earlier than here.
wxASSERT(false);
pastedClip->mSequence->ConvertToSampleFormat(mSequence->GetSampleFormat());
}
bool result = false;
if (mSequence->Paste(s0, pastedClip->mSequence))
{
MarkChanged();