From 1eda9c0b01039f29d230a46cda9f2290bbd1f62b Mon Sep 17 00:00:00 2001 From: Minty-Meeo <45425365+Minty-Meeo@users.noreply.github.com> Date: Fri, 24 Mar 2023 12:32:50 -0500 Subject: [PATCH] Resolve [-Wzero-as-null-pointer-constant] --- CMakeLists.txt | 2 +- include/BPMDetect.h | 2 +- include/FIFOSamplePipe.h | 6 +++--- source/Android-lib/jni/soundtouch-jni.cpp | 8 ++++---- source/SoundStretch/RunParameters.cpp | 6 +++--- source/SoundStretch/WavFile.cpp | 12 ++++++------ source/SoundStretch/main.cpp | 4 ++-- source/SoundTouch/AAFilter.cpp | 2 +- source/SoundTouch/BPMDetect.cpp | 4 ++-- source/SoundTouch/FIFOSampleBuffer.cpp | 10 +++++----- source/SoundTouch/FIRFilter.cpp | 12 ++++++------ source/SoundTouch/RateTransposer.cpp | 2 +- source/SoundTouch/SoundTouch.cpp | 6 +++--- source/SoundTouch/TDStretch.cpp | 6 +++--- source/SoundTouch/TDStretch.h | 2 +- source/SoundTouch/mmx_optimized.cpp | 4 ++-- source/SoundTouch/sse_optimized.cpp | 14 +++++++------- .../LazarusTest/SoundTouchDLL.pas | 2 +- source/SoundTouchDLL/SoundTouchDLL.cpp | 18 +++++++++--------- 19 files changed, 61 insertions(+), 61 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index caa04d3..b6718fb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ if(MSVC) set(COMPILE_DEFINITIONS /O2 /fp:fast) set(COMPILE_OPTIONS ) else() - set(COMPILE_OPTIONS -Ofast -Wall -Wextra -Wno-unknown-pragmas) + set(COMPILE_OPTIONS -Ofast -Wall -Wextra -Wzero-as-null-pointer-constant -Wno-unknown-pragmas) endif() ##################### diff --git a/include/BPMDetect.h b/include/BPMDetect.h index 8ece784..763266f 100644 --- a/include/BPMDetect.h +++ b/include/BPMDetect.h @@ -196,7 +196,7 @@ namespace soundtouch /// - "values" receive array of beat detection strengths /// - max_num indicates max.size of "pos" and "values" array. /// - /// You can query a suitable array sized by calling this with NULL in "pos" & "values". + /// You can query a suitable array sized by calling this with nullptr in "pos" & "values". /// /// \return number of beats in the arrays. int getBeats(float *pos, float *strength, int max_num); diff --git a/include/FIFOSamplePipe.h b/include/FIFOSamplePipe.h index 663c5c6..2ce5178 100644 --- a/include/FIFOSamplePipe.h +++ b/include/FIFOSamplePipe.h @@ -144,8 +144,8 @@ protected: /// Sets output pipe. void setOutPipe(FIFOSamplePipe *pOutput) { - assert(output == NULL); - assert(pOutput != NULL); + assert(output == nullptr); + assert(pOutput != nullptr); output = pOutput; } @@ -153,7 +153,7 @@ protected: /// 'setOutPipe' function. FIFOProcessor() { - output = NULL; + output = nullptr; } /// Constructor. Configures output pipe. diff --git a/source/Android-lib/jni/soundtouch-jni.cpp b/source/Android-lib/jni/soundtouch-jni.cpp index 83cb446..01fdab0 100644 --- a/source/Android-lib/jni/soundtouch-jni.cpp +++ b/source/Android-lib/jni/soundtouch-jni.cpp @@ -46,7 +46,7 @@ static void _setErrmsg(const char *msg) #include extern pthread_key_t gomp_tls_key; -static void * _p_gomp_tls = NULL; +static void * _p_gomp_tls = nullptr; /// Function to initialize threading for OpenMP. /// @@ -54,7 +54,7 @@ static void * _p_gomp_tls = NULL; /// called from the Android App main thread because in the main thread the gomp_tls storage is /// properly set, however, Android does not properly initialize gomp_tls storage for other threads. /// Thus if OpenMP routines are invoked from some other thread than the main thread, -/// the OpenMP routine will crash the application due to NULL pointer access on uninitialized storage. +/// the OpenMP routine will crash the application due to nullptr access on uninitialized storage. /// /// This workaround stores the gomp_tls storage from main thread, and copies to other threads. /// In order this to work, the Application main thread needws to call at least "getVersionString" @@ -63,7 +63,7 @@ static int _init_threading(bool warn) { void *ptr = pthread_getspecific(gomp_tls_key); LOGV("JNI thread-specific TLS storage %ld", (long)ptr); - if (ptr == NULL) + if (ptr == nullptr) { LOGV("JNI set missing TLS storage to %ld", (long)_p_gomp_tls); pthread_setspecific(gomp_tls_key, _p_gomp_tls); @@ -74,7 +74,7 @@ static int _init_threading(bool warn) _p_gomp_tls = ptr; } // Where critical, show warning if storage still not properly initialized - if ((warn) && (_p_gomp_tls == NULL)) + if ((warn) && (_p_gomp_tls == nullptr)) { _setErrmsg("Error - OpenMP threading not properly initialized: Call SoundTouch.getVersionString() from the App main thread!"); return -1; diff --git a/source/SoundStretch/RunParameters.cpp b/source/SoundStretch/RunParameters.cpp index 1960a35..54b3b62 100644 --- a/source/SoundStretch/RunParameters.cpp +++ b/source/SoundStretch/RunParameters.cpp @@ -115,8 +115,8 @@ RunParameters::RunParameters(const int nParams, const char * const paramStr[]) ST_THROW_RT_ERROR(msg.c_str()); } - inFileName = NULL; - outFileName = NULL; + inFileName = nullptr; + outFileName = nullptr; tempoDelta = 0; pitchDelta = 0; rateDelta = 0; @@ -133,7 +133,7 @@ RunParameters::RunParameters(const int nParams, const char * const paramStr[]) if (outFileName[0] == '-') { // no outputfile name was given but parameters - outFileName = NULL; + outFileName = nullptr; nFirstParam = 2; } else diff --git a/source/SoundStretch/WavFile.cpp b/source/SoundStretch/WavFile.cpp index 52efb1d..459e2ed 100644 --- a/source/SoundStretch/WavFile.cpp +++ b/source/SoundStretch/WavFile.cpp @@ -138,7 +138,7 @@ static const char dataStr[] = "data"; WavFileBase::WavFileBase() { - convBuff = NULL; + convBuff = nullptr; convBuffSize = 0; } @@ -173,7 +173,7 @@ WavInFile::WavInFile(const char *fileName) { // Try to open the file for reading fptr = fopen(fileName, "rb"); - if (fptr == NULL) + if (fptr == nullptr) { // didn't succeed string msg = "Error : Unable to open file \""; @@ -234,7 +234,7 @@ void WavInFile::init() WavInFile::~WavInFile() { if (fptr) fclose(fptr); - fptr = NULL; + fptr = nullptr; } @@ -707,7 +707,7 @@ WavOutFile::WavOutFile(const char *fileName, int sampleRate, int bits, int chann { bytesWritten = 0; fptr = fopen(fileName, "wb"); - if (fptr == NULL) + if (fptr == nullptr) { string msg = "Error : Unable to open file \""; msg += fileName; @@ -725,7 +725,7 @@ WavOutFile::WavOutFile(FILE *file, int sampleRate, int bits, int channels) { bytesWritten = 0; fptr = file; - if (fptr == NULL) + if (fptr == nullptr) { string msg = "Error : Unable to access output file stream."; ST_THROW_RT_ERROR(msg.c_str()); @@ -740,7 +740,7 @@ WavOutFile::~WavOutFile() { finishHeader(); if (fptr) fclose(fptr); - fptr = NULL; + fptr = nullptr; } diff --git a/source/SoundStretch/main.cpp b/source/SoundStretch/main.cpp index 1742731..1651ce7 100644 --- a/source/SoundStretch/main.cpp +++ b/source/SoundStretch/main.cpp @@ -103,7 +103,7 @@ static void openFiles(WavInFile **inFile, WavOutFile **outFile, const RunParamet } else { - *outFile = NULL; + *outFile = nullptr; } } @@ -172,7 +172,7 @@ static void process(SoundTouch *pSoundTouch, WavInFile *inFile, WavOutFile *outF int buffSizeSamples; SAMPLETYPE sampleBuffer[BUFF_SIZE]; - if ((inFile == NULL) || (outFile == NULL)) return; // nothing to do. + if ((inFile == nullptr) || (outFile == nullptr)) return; // nothing to do. nChannels = (int)inFile->getNumChannels(); assert(nChannels > 0); diff --git a/source/SoundTouch/AAFilter.cpp b/source/SoundTouch/AAFilter.cpp index 76a3da6..89c54cc 100644 --- a/source/SoundTouch/AAFilter.cpp +++ b/source/SoundTouch/AAFilter.cpp @@ -54,7 +54,7 @@ using namespace soundtouch; static void _DEBUG_SAVE_AAFIR_COEFFS(SAMPLETYPE *coeffs, int len) { FILE *fptr = fopen("aa_filter_coeffs.txt", "wt"); - if (fptr == NULL) return; + if (fptr == nullptr) return; for (int i = 0; i < len; i ++) { diff --git a/source/SoundTouch/BPMDetect.cpp b/source/SoundTouch/BPMDetect.cpp index 920e968..4c11a2e 100644 --- a/source/SoundTouch/BPMDetect.cpp +++ b/source/SoundTouch/BPMDetect.cpp @@ -554,13 +554,13 @@ float BPMDetect::getBpm() /// - "values" receive array of beat detection strengths /// - max_num indicates max.size of "pos" and "values" array. /// -/// You can query a suitable array sized by calling this with NULL in "pos" & "values". +/// You can query a suitable array sized by calling this with nullptr in "pos" & "values". /// /// \return number of beats in the arrays. int BPMDetect::getBeats(float *pos, float *values, int max_num) { int num = (int)beats.size(); - if ((!pos) || (!values)) return num; // pos or values NULL, return just size + if ((!pos) || (!values)) return num; // pos or values nullptr, return just size for (int i = 0; (i < num) && (i < max_num); i++) { diff --git a/source/SoundTouch/FIFOSampleBuffer.cpp b/source/SoundTouch/FIFOSampleBuffer.cpp index 15d1fc7..420e0d7 100644 --- a/source/SoundTouch/FIFOSampleBuffer.cpp +++ b/source/SoundTouch/FIFOSampleBuffer.cpp @@ -50,8 +50,8 @@ FIFOSampleBuffer::FIFOSampleBuffer(int numChannels) { assert(numChannels > 0); sizeInBytes = 0; // reasonable initial value - buffer = NULL; - bufferUnaligned = NULL; + buffer = nullptr; + bufferUnaligned = nullptr; samplesInBuffer = 0; bufferPos = 0; channels = (uint)numChannels; @@ -63,8 +63,8 @@ FIFOSampleBuffer::FIFOSampleBuffer(int numChannels) FIFOSampleBuffer::~FIFOSampleBuffer() { delete[] bufferUnaligned; - bufferUnaligned = NULL; - buffer = NULL; + bufferUnaligned = nullptr; + buffer = nullptr; } @@ -166,7 +166,7 @@ void FIFOSampleBuffer::ensureCapacity(uint capacityRequirement) sizeInBytes = (capacityRequirement * channels * sizeof(SAMPLETYPE) + 4095) & (uint)-4096; assert(sizeInBytes % 2 == 0); tempUnaligned = new SAMPLETYPE[sizeInBytes / sizeof(SAMPLETYPE) + 16 / sizeof(SAMPLETYPE)]; - if (tempUnaligned == NULL) + if (tempUnaligned == nullptr) { ST_THROW_RT_ERROR("Couldn't allocate memory!\n"); } diff --git a/source/SoundTouch/FIRFilter.cpp b/source/SoundTouch/FIRFilter.cpp index edfeb41..473ca07 100644 --- a/source/SoundTouch/FIRFilter.cpp +++ b/source/SoundTouch/FIRFilter.cpp @@ -59,8 +59,8 @@ FIRFilter::FIRFilter() resultDivider = 0; length = 0; lengthDiv8 = 0; - filterCoeffs = NULL; - filterCoeffsStereo = NULL; + filterCoeffs = nullptr; + filterCoeffsStereo = nullptr; } @@ -78,7 +78,7 @@ uint FIRFilter::evaluateFilterStereo(SAMPLETYPE *dest, const SAMPLETYPE *src, ui // hint compiler autovectorization that loop length is divisible by 8 uint ilength = length & -8; - assert((length != 0) && (length == ilength) && (src != NULL) && (dest != NULL) && (filterCoeffs != NULL)); + assert((length != 0) && (length == ilength) && (src != nullptr) && (dest != nullptr) && (filterCoeffs != nullptr)); assert(numSamples > ilength); end = 2 * (numSamples - ilength); @@ -152,9 +152,9 @@ uint FIRFilter::evaluateFilterMulti(SAMPLETYPE *dest, const SAMPLETYPE *src, uin int j, end; assert(length != 0); - assert(src != NULL); - assert(dest != NULL); - assert(filterCoeffs != NULL); + assert(src != nullptr); + assert(dest != nullptr); + assert(filterCoeffs != nullptr); assert(numChannels < 16); // hint compiler autovectorization that loop length is divisible by 8 diff --git a/source/SoundTouch/RateTransposer.cpp b/source/SoundTouch/RateTransposer.cpp index 1663b60..a48ea86 100644 --- a/source/SoundTouch/RateTransposer.cpp +++ b/source/SoundTouch/RateTransposer.cpp @@ -307,7 +307,7 @@ TransposerBase *TransposerBase::newInstance() default: assert(false); - return NULL; + return nullptr; } #endif } diff --git a/source/SoundTouch/SoundTouch.cpp b/source/SoundTouch/SoundTouch.cpp index 1618884..cb161f0 100644 --- a/source/SoundTouch/SoundTouch.cpp +++ b/source/SoundTouch/SoundTouch.cpp @@ -413,15 +413,15 @@ int SoundTouch::getSetting(int settingId) const return (uint)pTDStretch->isQuickSeekEnabled(); case SETTING_SEQUENCE_MS: - pTDStretch->getParameters(NULL, &temp, NULL, NULL); + pTDStretch->getParameters(nullptr, &temp, nullptr, nullptr); return temp; case SETTING_SEEKWINDOW_MS: - pTDStretch->getParameters(NULL, NULL, &temp, NULL); + pTDStretch->getParameters(nullptr, nullptr, &temp, nullptr); return temp; case SETTING_OVERLAP_MS: - pTDStretch->getParameters(NULL, NULL, NULL, &temp); + pTDStretch->getParameters(nullptr, nullptr, nullptr, &temp); return temp; case SETTING_NOMINAL_INPUT_SEQUENCE : diff --git a/source/SoundTouch/TDStretch.cpp b/source/SoundTouch/TDStretch.cpp index e416a3a..157f0e4 100644 --- a/source/SoundTouch/TDStretch.cpp +++ b/source/SoundTouch/TDStretch.cpp @@ -66,8 +66,8 @@ TDStretch::TDStretch() : FIFOProcessor(&outputBuffer) bQuickSeek = false; channels = 2; - pMidBuffer = NULL; - pMidBufferUnaligned = NULL; + pMidBuffer = nullptr; + pMidBufferUnaligned = nullptr; overlapLength = 0; bAutoSeqSetting = true; @@ -143,7 +143,7 @@ void TDStretch::setParameters(int aSampleRate, int aSequenceMS, /// Get routine control parameters, see setParameters() function. -/// Any of the parameters to this function can be NULL, in such case corresponding parameter +/// Any of the parameters to this function can be nullptr, in such case corresponding parameter /// value isn't returned. void TDStretch::getParameters(int *pSampleRate, int *pSequenceMs, int *pSeekWindowMs, int *pOverlapMs) const { diff --git a/source/SoundTouch/TDStretch.h b/source/SoundTouch/TDStretch.h index 71c0853..6fddc23 100644 --- a/source/SoundTouch/TDStretch.h +++ b/source/SoundTouch/TDStretch.h @@ -217,7 +217,7 @@ public: ); /// Get routine control parameters, see setParameters() function. - /// Any of the parameters to this function can be NULL, in such case corresponding parameter + /// Any of the parameters to this function can be nullptr, in such case corresponding parameter /// value isn't returned. void getParameters(int *pSampleRate, int *pSequenceMs, int *pSeekWindowMs, int *pOverlapMs) const; diff --git a/source/SoundTouch/mmx_optimized.cpp b/source/SoundTouch/mmx_optimized.cpp index 741ba4f..0a2949c 100644 --- a/source/SoundTouch/mmx_optimized.cpp +++ b/source/SoundTouch/mmx_optimized.cpp @@ -294,8 +294,8 @@ void TDStretchMMX::overlapStereo(short *output, const short *input) const FIRFilterMMX::FIRFilterMMX() : FIRFilter() { - filterCoeffsAlign = NULL; - filterCoeffsUnalign = NULL; + filterCoeffsAlign = nullptr; + filterCoeffsUnalign = nullptr; } diff --git a/source/SoundTouch/sse_optimized.cpp b/source/SoundTouch/sse_optimized.cpp index c17f443..ebcc441 100644 --- a/source/SoundTouch/sse_optimized.cpp +++ b/source/SoundTouch/sse_optimized.cpp @@ -195,16 +195,16 @@ double TDStretchSSE::calcCrossCorrAccumulate(const float *pV1, const float *pV2, FIRFilterSSE::FIRFilterSSE() : FIRFilter() { - filterCoeffsAlign = NULL; - filterCoeffsUnalign = NULL; + filterCoeffsAlign = nullptr; + filterCoeffsUnalign = nullptr; } FIRFilterSSE::~FIRFilterSSE() { delete[] filterCoeffsUnalign; - filterCoeffsAlign = NULL; - filterCoeffsUnalign = NULL; + filterCoeffsAlign = nullptr; + filterCoeffsUnalign = nullptr; } @@ -245,10 +245,10 @@ uint FIRFilterSSE::evaluateFilterStereo(float *dest, const float *source, uint n if (count < 2) return 0; - assert(source != NULL); - assert(dest != NULL); + assert(source != nullptr); + assert(dest != nullptr); assert((length % 8) == 0); - assert(filterCoeffsAlign != NULL); + assert(filterCoeffsAlign != nullptr); assert(((ulongptr)filterCoeffsAlign) % 16 == 0); // filter is evaluated for two stereo samples with each iteration, thus use of 'j += 2' diff --git a/source/SoundTouchDLL/LazarusTest/SoundTouchDLL.pas b/source/SoundTouchDLL/LazarusTest/SoundTouchDLL.pas index 5e117aa..853dc28 100644 --- a/source/SoundTouchDLL/LazarusTest/SoundTouchDLL.pas +++ b/source/SoundTouchDLL/LazarusTest/SoundTouchDLL.pas @@ -137,7 +137,7 @@ type /// Receive ready samples from the processing pipeline. /// - /// if called with outBuffer=NULL, just reduces amount of ready samples within the pipeline. + /// if called with outBuffer=nullptr, just reduces amount of ready samples within the pipeline. TSoundTouchReceiveSamples = function (Handle: TSoundTouchHandle; OutBuffer: PSingle; //< Buffer where to copy output samples. MaxSamples: Integer //< How many samples to receive at max. diff --git a/source/SoundTouchDLL/SoundTouchDLL.cpp b/source/SoundTouchDLL/SoundTouchDLL.cpp index 3f78cca..28ebfba 100644 --- a/source/SoundTouchDLL/SoundTouchDLL.cpp +++ b/source/SoundTouchDLL/SoundTouchDLL.cpp @@ -90,10 +90,10 @@ SOUNDTOUCHDLL_API HANDLE __cdecl soundtouch_createInstance() { tmp->dwMagic = STMAGIC; tmp->pst = new SoundTouch(); - if (tmp->pst == NULL) + if (tmp->pst == nullptr) { delete tmp; - tmp = NULL; + tmp = nullptr; } } return (HANDLE)tmp; @@ -107,7 +107,7 @@ SOUNDTOUCHDLL_API void __cdecl soundtouch_destroyInstance(HANDLE h) sth->dwMagic = 0; if (sth->pst) delete sth->pst; - sth->pst = NULL; + sth->pst = nullptr; delete sth; } @@ -375,7 +375,7 @@ SOUNDTOUCHDLL_API uint __cdecl soundtouch_numUnprocessedSamples(HANDLE h) /// Receive ready samples from the processing pipeline. /// -/// if called with outBuffer=NULL, just reduces amount of ready samples within the pipeline. +/// if called with outBuffer=nullptr, just reduces amount of ready samples within the pipeline. SOUNDTOUCHDLL_API uint __cdecl soundtouch_receiveSamples(HANDLE h, SAMPLETYPE *outBuffer, ///< Buffer where to copy output samples. unsigned int maxSamples ///< How many samples to receive at max. @@ -406,7 +406,7 @@ SOUNDTOUCHDLL_API uint __cdecl soundtouch_receiveSamples_i16(HANDLE h, if (sth->dwMagic != STMAGIC) return 0; uint outTotal = 0; - if (outBuffer == NULL) + if (outBuffer == nullptr) { // only reduce sample count, not receive samples return sth->pst->receiveSamples(maxSamples); @@ -480,12 +480,12 @@ SOUNDTOUCHDLL_API HANDLE __cdecl bpm_createInstance(int numChannels, int sampleR } catch (const std::exception&) { - tmp->pbpm = NULL; + tmp->pbpm = nullptr; } - if (tmp->pbpm == NULL) + if (tmp->pbpm == nullptr) { delete tmp; - tmp = NULL; + tmp = nullptr; } } return (HANDLE)tmp; @@ -499,7 +499,7 @@ SOUNDTOUCHDLL_API void __cdecl bpm_destroyInstance(HANDLE h) sth->dwMagic = 0; if (sth->pbpm) delete sth->pbpm; - sth->pbpm = NULL; + sth->pbpm = nullptr; delete sth; }