Skip to content

Commit

Permalink
Avoiding potential ArgumentOutOfRangeException in Sample/WaveAggregat…
Browse files Browse the repository at this point in the history
…orBase class.
  • Loading branch information
filoe committed Jul 23, 2016
1 parent be67770 commit 2a39388
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions CSCore/SampleAggregatorBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ public SampleAggregatorBase(ISampleSource source)
public virtual int Read(float[] buffer, int offset, int count)
{
if (offset % WaveFormat.Channels != 0)
throw new ArgumentOutOfRangeException("offset");
offset -= offset % WaveFormat.Channels;
if (count % WaveFormat.Channels != 0)
throw new ArgumentOutOfRangeException("count");
count -= count % WaveFormat.Channels;

return BaseSource.Read(buffer, offset, count);
}
Expand Down
7 changes: 6 additions & 1 deletion CSCore/WaveAggregatorBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace CSCore
/// <summary>
/// Base class for all wave aggregators.
/// </summary>
public abstract class WaveAggregatorBase : IWaveSource, IAggregator<byte, IWaveSource>
public abstract class WaveAggregatorBase : IWaveAggregator
{
private IWaveSource _baseSource;
private bool _disposed;
Expand Down Expand Up @@ -77,6 +77,11 @@ public virtual WaveFormat WaveFormat
/// <returns>The total number of bytes read into the buffer.</returns>
public virtual int Read(byte[] buffer, int offset, int count)
{
if (offset % WaveFormat.Channels != 0)
offset -= offset % WaveFormat.Channels;
if (count % WaveFormat.Channels != 0)
count -= count % WaveFormat.Channels;

return BaseSource.Read(buffer, offset, count);
}

Expand Down

0 comments on commit 2a39388

Please sign in to comment.