diff --git a/src/engine/sample.cpp b/src/engine/sample.cpp index 624337a68..e506321d1 100644 --- a/src/engine/sample.cpp +++ b/src/engine/sample.cpp @@ -543,7 +543,11 @@ bool DivSample::saveRaw(const char* path) { } // 16-bit memory is padded to 512, to make things easier for ADPCM-A/B. -bool DivSample::initInternal(DivSampleDepth d, unsigned int count) { +bool DivSample::initInternal(DivSampleDepth d, int count) { + if (count<0) { + logE("initInternal(%d,%d) - NEGATIVE!",(int)d,count); + return false; + } logV("initInternal(%d,%d)",(int)d,count); switch (d) { case DIV_SAMPLE_DEPTH_1BIT: // 1-bit @@ -650,8 +654,11 @@ bool DivSample::initInternal(DivSampleDepth d, unsigned int count) { return true; } -bool DivSample::init(unsigned int count) { - if (count>16777215) return false; +bool DivSample::init(int count) { + if (count<0 || count>16777215) { + logE("tried to init sample with length %d!",count); + return false; + } if (!initInternal(depth,count)) return false; setSampleCount(count); return true; diff --git a/src/engine/sample.h b/src/engine/sample.h index c671f95d4..609520c7e 100644 --- a/src/engine/sample.h +++ b/src/engine/sample.h @@ -236,14 +236,14 @@ struct DivSample { * @param count number of samples. * @return whether it was successful. */ - bool initInternal(DivSampleDepth d, unsigned int count); + bool initInternal(DivSampleDepth d, int count); /** * initialize sample data. make sure you have set `depth` before doing so. * @param count number of samples. * @return whether it was successful. */ - bool init(unsigned int count); + bool init(int count); /** * resize sample data. make sure the sample has been initialized before doing so.