From: Paul Davis Date: Wed, 28 Oct 2009 21:02:28 +0000 (+0000) Subject: potential fix for zoom-related crash involving array overrun during peak generation X-Git-Tag: 2.8.16~675 X-Git-Url: https://main.carlh.net/gitweb/?a=commitdiff_plain;h=836591b6b5aa8d0e439004152e3941150f0fb538;p=ardour.git potential fix for zoom-related crash involving array overrun during peak generation git-svn-id: svn://localhost/ardour2/branches/2.0-ongoing@5960 d708f5d6-7413-0410-9779-e7cbd77b26cf --- diff --git a/libs/ardour/audiosource.cc b/libs/ardour/audiosource.cc index 36a667d109..5bd9712762 100644 --- a/libs/ardour/audiosource.cc +++ b/libs/ardour/audiosource.cc @@ -523,21 +523,28 @@ AudioSource::read_peaks_with_fpp (PeakData *peaks, nframes_t npeaks, nframes_t s if (i == frames_read) { - to_read = min (chunksize, (_length - current_frame)); + if (current_frame >= _length) { - if (to_read == 0) { - /* XXX ARGH .. out by one error ... need to figure out why this happens - and fix it rather than do this band-aid move. + /* hmm, error condition - we've reached the end of the file + without generating all the peak data. cook up a zero-filled + data buffer and then use it. this is simpler than + adjusting zero_fill and npeaks and then breaking out of + this loop early */ - zero_fill = npeaks - nvisual_peaks; - break; - } - if ((frames_read = read_unlocked (raw_staging, current_frame, to_read)) == 0) { - error << string_compose(_("AudioSource[%1]: peak read - cannot read %2 samples at offset %3 of %4 (%5)"), - _name, to_read, current_frame, _length, strerror (errno)) - << endmsg; - goto out; + memset (raw_staging, 0, sizeof (Sample) * chunksize); + + } else { + + to_read = min (chunksize, (_length - current_frame)); + + + if ((frames_read = read_unlocked (raw_staging, current_frame, to_read)) == 0) { + error << string_compose(_("AudioSource[%1]: peak read - cannot read %2 samples at offset %3 of %4 (%5)"), + _name, to_read, current_frame, _length, strerror (errno)) + << endmsg; + goto out; + } } i = 0;