diff options
author | Marco Nelissen <marcone@google.com> | 2019-06-19 10:52:12 -0700 |
---|---|---|
committer | Marco Nelissen <marcone@google.com> | 2019-06-19 12:40:21 -0700 |
commit | 719194352dbd4ab8d091b4c9739fdb555246597e (patch) | |
tree | 9537d95b9a666919bb59c6d07a7dda01302e8ce8 /arm-wt-22k | |
parent | 7dd71801813e0a0df71d500d6bbe7a6432334c9b (diff) | |
download | sonivox-719194352dbd4ab8d091b4c9739fdb555246597e.tar.gz |
Avoid underflows in loop counters
Constructs like
while (counter--) { ... }
will cause an abort if unsigned overflow sanitization is turned on
and 'counter' is an unsigned variable.
Changing these to
while (counter) { counter--; ... }
avoids that, which allows unsigned overflow sanitization to be turned on.
Test: decoded midi files with unsigned overflow sanitizer turned on.
Change-Id: I7d791c4431d6692b9081333ff3685a449b143e3a
Diffstat (limited to 'arm-wt-22k')
-rw-r--r-- | arm-wt-22k/lib_src/eas_mdls.c | 4 | ||||
-rw-r--r-- | arm-wt-22k/lib_src/eas_mixer.c | 3 | ||||
-rw-r--r-- | arm-wt-22k/lib_src/eas_smf.c | 6 |
3 files changed, 8 insertions, 5 deletions
diff --git a/arm-wt-22k/lib_src/eas_mdls.c b/arm-wt-22k/lib_src/eas_mdls.c index b172881..4d45d8b 100644 --- a/arm-wt-22k/lib_src/eas_mdls.c +++ b/arm-wt-22k/lib_src/eas_mdls.c @@ -2044,9 +2044,9 @@ static EAS_RESULT Parse_art (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, S_DLS if ((result = EAS_HWFileSeek(pDLSData->hwInstData, pDLSData->fileHandle, pos)) != EAS_SUCCESS) return result; - while (numConnections--) + while (numConnections) { - + numConnections--; /* read the connection data */ if ((result = EAS_HWGetWord(pDLSData->hwInstData, pDLSData->fileHandle, &source, EAS_FALSE)) != EAS_SUCCESS) return result; diff --git a/arm-wt-22k/lib_src/eas_mixer.c b/arm-wt-22k/lib_src/eas_mixer.c index 0a839a8..9ccdaf8 100644 --- a/arm-wt-22k/lib_src/eas_mixer.c +++ b/arm-wt-22k/lib_src/eas_mixer.c @@ -266,9 +266,10 @@ void EAS_MixEnginePost (S_EAS_DATA *pEASData, EAS_I32 numSamples) void SynthMasterGain (long *pInputBuffer, EAS_PCM *pOutputBuffer, EAS_U16 nGain, EAS_U16 numSamples) { /* loop through the buffer */ - while (numSamples--) { + while (numSamples) { long s; + numSamples--; /* read a sample from the input buffer and add some guard bits */ s = *pInputBuffer++; diff --git a/arm-wt-22k/lib_src/eas_smf.c b/arm-wt-22k/lib_src/eas_smf.c index 72e89c3..48fc456 100644 --- a/arm-wt-22k/lib_src/eas_smf.c +++ b/arm-wt-22k/lib_src/eas_smf.c @@ -867,8 +867,9 @@ static EAS_RESULT SMF_ParseMetaEvent (S_EAS_DATA *pEASData, S_SMF_DATA *pSMFData { /* read the 3-byte timebase value */ temp = 0; - while (len--) + while (len) { + len--; if ((result = EAS_HWGetByte(pEASData->hwInstData, pSMFStream->fileHandle, &c)) != EAS_SUCCESS) return result; temp = (temp << 8) | c; @@ -956,8 +957,9 @@ static EAS_RESULT SMF_ParseSysEx (S_EAS_DATA *pEASData, S_SMF_DATA *pSMFData, S_ } /* feed the SysEx to the stream parser */ - while (len--) + while (len) { + len--; if ((result = EAS_HWGetByte(pEASData->hwInstData, pSMFStream->fileHandle, &c)) != EAS_SUCCESS) return result; if ((result = EAS_ParseMIDIStream(pEASData, pSMFData->pSynth, &pSMFStream->midiStream, c, parserMode)) != EAS_SUCCESS) |