From 02df9b2e9a08afe9e86255133dd980cd4344a9c7 Mon Sep 17 00:00:00 2001 From: David Reid Date: Wed, 29 Jan 2020 18:00:12 +1000 Subject: [PATCH] Update dr_wav, dr_flac and dr_mp3. --- extras/dr_flac.h | 10 +++++++--- extras/dr_mp3.h | 12 ++++++++---- extras/dr_wav.h | 31 +++++++++++++++++++------------ 3 files changed, 34 insertions(+), 19 deletions(-) diff --git a/extras/dr_flac.h b/extras/dr_flac.h index c30574eb..7fb7a076 100644 --- a/extras/dr_flac.h +++ b/extras/dr_flac.h @@ -1,6 +1,6 @@ /* FLAC audio decoder. Choice of public domain or MIT-0. See license statements at the end of this file. -dr_flac - v0.12.3 - 2019-12-02 +dr_flac - v0.12.4 - 2020-01-29 David Reid - mackron@gmail.com */ @@ -4679,6 +4679,7 @@ static drflac_bool32 drflac__read_next_flac_frame_header(drflac_bs* bs, drflac_u } + DRFLAC_ASSERT(blockSize > 0); if (blockSize == 1) { header->blockSizeInPCMFrames = 192; } else if (blockSize >= 2 && blockSize <= 5) { @@ -10320,7 +10321,7 @@ drflac_bool32 drflac_seek_to_pcm_frame(drflac* pFlac, drflac_uint64 pcmFrameInde #endif { /* First try seeking via the seek table. If this fails, fall back to a brute force seek which is much slower. */ - if (!wasSuccessful && !pFlac->_noSeekTableSeek) { + if (/*!wasSuccessful && */!pFlac->_noSeekTableSeek) { wasSuccessful = drflac__seek_to_pcm_frame__seek_table(pFlac, pcmFrameIndex); } @@ -10737,6 +10738,9 @@ drflac_bool32 drflac_next_cuesheet_track(drflac_cuesheet_track_iterator* pIter, /* REVISION HISTORY ================ +v0.12.4 - 2020-01-29 + - Silence some static analysis warnings. + v0.12.3 - 2019-12-02 - Fix some warnings when compiling with GCC and the -Og flag. - Fix a crash in out-of-memory situations. @@ -11041,7 +11045,7 @@ For more information, please refer to =============================================================================== ALTERNATIVE 2 - MIT No Attribution =============================================================================== -Copyright 2018 David Reid +Copyright 2020 David Reid Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in diff --git a/extras/dr_mp3.h b/extras/dr_mp3.h index a2bacca3..40692003 100644 --- a/extras/dr_mp3.h +++ b/extras/dr_mp3.h @@ -1,6 +1,6 @@ /* MP3 audio decoder. Choice of public domain or MIT-0. See license statements at the end of this file. -dr_mp3 - v0.5.4 - 2019-12-02 +dr_mp3 - v0.5.5 - 2020-01-29 David Reid - mackron@gmail.com @@ -823,7 +823,7 @@ static void drmp3_L12_read_scalefactors(drmp3_bs *bs, drmp3_uint8 *pba, drmp3_ui if (mask & m) { int b = drmp3_bs_get_bits(bs, 6); - s = g_deq_L12[ba*3 - 6 + b % 3]*(1 << 21 >> b/3); + s = g_deq_L12[ba*3 - 6 + b % 3]*(int)(1 << 21 >> b/3); } *scf++ = s; } @@ -3872,7 +3872,7 @@ drmp3_int16* drmp3__full_read_and_close_s16(drmp3* pMP3, drmp3_config* pConfig, drmp3_uint64 newFramesCap; drmp3_int16* pNewFrames; - newFramesCap = framesCapacity * 2; + newFramesCap = framesCapacity * 2; if (newFramesCap < totalFramesRead + framesJustRead) { newFramesCap = totalFramesRead + framesJustRead; } @@ -3890,6 +3890,7 @@ drmp3_int16* drmp3__full_read_and_close_s16(drmp3* pMP3, drmp3_config* pConfig, } pFrames = pNewFrames; + framesCapacity = newFramesCap; } DRMP3_COPY_MEMORY(pFrames + totalFramesRead*pMP3->channels, temp, (size_t)(framesJustRead*pMP3->channels*sizeof(drmp3_int16))); @@ -4009,6 +4010,9 @@ DIFFERENCES BETWEEN minimp3 AND dr_mp3 /* REVISION HISTORY ================ +v0.5.5 - 2020-01-29 + - Fix a memory allocation bug in high level s16 decoding APIs. + v0.5.4 - 2019-12-02 - Fix a possible null pointer dereference when using custom memory allocators for realloc(). @@ -4182,7 +4186,7 @@ For more information, please refer to =============================================================================== ALTERNATIVE 2 - MIT No Attribution =============================================================================== -Copyright 2018 David Reid +Copyright 2020 David Reid Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in diff --git a/extras/dr_wav.h b/extras/dr_wav.h index fe1e99b4..42d81a68 100644 --- a/extras/dr_wav.h +++ b/extras/dr_wav.h @@ -1,6 +1,6 @@ /* WAV audio loader and writer. Choice of public domain or MIT-0. See license statements at the end of this file. -dr_wav - v0.11.3 - 2020-01-12 +dr_wav - v0.11.4 - 2020-01-29 David Reid - mackron@gmail.com */ @@ -1100,14 +1100,14 @@ static const drwav_uint8 drwavGUID_W64_SMPL[16] = {0x73,0x6D,0x70,0x6C, 0xF3,0xA static DRWAV_INLINE drwav_bool32 drwav__guid_equal(const drwav_uint8 a[16], const drwav_uint8 b[16]) { - const drwav_uint32* a32 = (const drwav_uint32*)a; - const drwav_uint32* b32 = (const drwav_uint32*)b; + int i; + for (i = 0; i < 16; i += 1) { + if (a[i] != b[i]) { + return DRWAV_FALSE; + } + } - return - a32[0] == b32[0] && - a32[1] == b32[1] && - a32[2] == b32[2] && - a32[3] == b32[3]; + return DRWAV_TRUE; } static DRWAV_INLINE drwav_bool32 drwav__fourcc_equal(const unsigned char* a, const char* b) @@ -3579,7 +3579,8 @@ static void drwav__pcm_to_s16(drwav_int16* pOut, const unsigned char* pIn, size_ unsigned int shift = (8 - bytesPerSample) * 8; unsigned int j; - for (j = 0; j < bytesPerSample && j < 8; j += 1) { + for (j = 0; j < bytesPerSample; j += 1) { + DRWAV_ASSERT(j < 8); sample |= (drwav_uint64)(pIn[j]) << shift; shift += 8; } @@ -3901,7 +3902,8 @@ static void drwav__pcm_to_f32(float* pOut, const unsigned char* pIn, size_t samp unsigned int shift = (8 - bytesPerSample) * 8; unsigned int j; - for (j = 0; j < bytesPerSample && j < 8; j += 1) { + for (j = 0; j < bytesPerSample; j += 1) { + DRWAV_ASSERT(j < 8); sample |= (drwav_uint64)(pIn[j]) << shift; shift += 8; } @@ -4051,7 +4053,7 @@ drwav_uint64 drwav_read_pcm_frames_f32__alaw(drwav* pWav, drwav_uint64 framesToR totalFramesRead = 0; - while (bytesPerFrame > 0) { + while (framesToRead > 0) { drwav_uint64 framesRead = drwav_read_pcm_frames(pWav, drwav_min(framesToRead, sizeof(sampleData)/bytesPerFrame), sampleData); if (framesRead == 0) { break; @@ -4303,7 +4305,8 @@ static void drwav__pcm_to_s32(drwav_int32* pOut, const unsigned char* pIn, size_ unsigned int shift = (8 - bytesPerSample) * 8; unsigned int j; - for (j = 0; j < bytesPerSample && j < 8; j += 1) { + for (j = 0; j < bytesPerSample; j += 1) { + DRWAV_ASSERT(j < 8); sample |= (drwav_uint64)(pIn[j]) << shift; shift += 8; } @@ -5052,6 +5055,10 @@ void drwav_free(void* p, const drwav_allocation_callbacks* pAllocationCallbacks) /* REVISION HISTORY ================ +v0.11.4 - 2020-01-29 + - Fix some static analysis warnings. + - Fix a bug when reading f32 samples from an A-law encoded stream. + v0.11.3 - 2020-01-12 - Minor changes to some f32 format conversion routines. - Minor bug fix for ADPCM conversion when end of file is reached.