1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-10-15 07:01:18 +02:00

Make many counts of tracks and channels unsigned...

... And in some places where a library uses signed types, assert that
the reported number is not negative.

What led me to this, is that there are many places where a size_t value for
an allocation is the product of a number of channels and some other number.
This commit is contained in:
Paul Licameli
2016-09-02 15:53:09 -04:00
parent ef23de6a60
commit 67cec5ad83
81 changed files with 272 additions and 262 deletions

View File

@@ -109,7 +109,7 @@ public:
private:
SFFile mFile;
SF_INFO mInfo;
const SF_INFO mInfo;
sampleFormat mFormat;
};
@@ -194,6 +194,8 @@ PCMImportFileHandle::PCMImportFileHandle(wxString name,
mFile(std::move(file)),
mInfo(info)
{
wxASSERT(info.channels >= 0);
//
// Figure out the format to use.
//
@@ -432,6 +434,8 @@ int PCMImportFileHandle::Import(TrackFactory *trackFactory,
// PRL: guard against excessive memory buffer allocation in case of many channels
using type = decltype(maxBlockSize);
if (mInfo.channels < 1)
return eProgressFailed;
auto maxBlock = std::min(maxBlockSize,
std::numeric_limits<type>::max() /
(mInfo.channels * SAMPLE_SIZE(mFormat))
@@ -440,6 +444,7 @@ int PCMImportFileHandle::Import(TrackFactory *trackFactory,
return eProgressFailed;
SampleBuffer srcbuffer;
wxASSERT(mInfo.channels >= 0);
while (NULL == srcbuffer.Allocate(maxBlock * mInfo.channels, mFormat).ptr())
{
maxBlock >>= 1;