Closed bwrsandman closed 1 year ago
Thanks. This is a weird one because there are literal asserts in there to account for this like you mentioned. It feels like for some reason the compilers are not recognizing those asserts:
DRMP3_ASSERT(pMP3->pData != NULL);
DRMP3_ASSERT(pMP3->dataCapacity > 0);
pcmFramesRead = drmp3dec_decode_frame(&pMP3->decoder, pMP3->pData + pMP3->dataConsumed, (int)pMP3->dataSize, pPCMFrames, &info); /* <-- Safe size_t -> int conversion thanks to the check above. */
I'm almost wondering if maybe I just do a normal run-time check for pData
being null and just returning 0. Have you by chance tried that to see if it cleans up that warning? I don't like the idea of modifying drmp3dec_decode_frame()
simply because that code is from minimp3 which I'm not fully intimate with.
I'm not really the biggest fan of the nonnull
thing because it just feels a bit hacky, and I'd be nice to avoid compiler-specific stuff if possible. But that said, if I need to do a compiler-specific thing so be it.
I tried what you said and naively returned 0. This seems to silence the error.
It also complains about this move operation. https://github.com/mackron/dr_libs/blob/master/dr_mp3.h#L2725
I've pushed a potential fix to clean up this warning to the dev branch. Are you able to try that?
That seems to have fixed it.
OK, that's good to hear. The fact that the static analyzer is recognizing the runtime check indicates to me that it's not detecting or recognizing the assert for some reason. In any case I'll get this released shortly.
Could be due to NDEBUG
I've updated the master branch with this change. Version 0.6.37.
I've updated dr_wav.h and theres this new one that popped up.
warning: Array access (from variable 'pBufferOut') results in a null pointer dereference [clang-analyzer-core.NullDereference]
((drwav_uint8*)pBufferOut)[iSample] += 128;
^
Thanks. That's a genuine bug. I've gone ahead and fixed that in the dev branch.
I know this is an esoteric warning but clang-analyzer warns that even though calls to
drmp3dec_decode_frame
have asserts to make suremp3
is not null, the parameter itself is not marked as non-null.Since the parameter is plugged into
memcpy
without checking, it emits this warning on clang and gcc.externals/dr_libs/dr_mp3.h:734: expanded from macro 'DRMP3_COPY_MEMORY'
src/Audio/MpegAudioDecoder.cpp:28: Calling 'drmp3_get_pcm_frame_count'
externals/dr_libs/dr_mp3.h:3991: Calling 'drmp3_get_mp3_and_pcm_frame_count'
externals/dr_libs/dr_mp3.h:3933: 'pMP3' is not equal to NULL
externals/dr_libs/dr_mp3.h:3933: Taking false branch
externals/dr_libs/dr_mp3.h:3943: Assuming field 'onSeek' is not equal to NULL
externals/dr_libs/dr_mp3.h:3943: Taking false branch
externals/dr_libs/dr_mp3.h:3950: Calling 'drmp3_seek_to_start_of_stream'
externals/dr_libs/dr_mp3.h:3773: Calling 'drmp3__on_seek'
externals/dr_libs/dr_mp3.h:2600: Assuming the condition is false
externals/dr_libs/dr_mp3.h:2600: Taking false branch
externals/dr_libs/dr_mp3.h:2604: 'origin' is equal to drmp3_seek_origin_start
externals/dr_libs/dr_mp3.h:2604: Taking true branch
externals/dr_libs/dr_mp3.h:2610: Returning without writing to 'pMP3->atEnd', which participates in a condition later
externals/dr_libs/dr_mp3.h:2610: Returning without writing to 'pMP3->pData'
externals/dr_libs/dr_mp3.h:3773: Returning from 'drmp3__on_seek'
externals/dr_libs/dr_mp3.h:3773: Taking false branch
externals/dr_libs/dr_mp3.h:3778: Calling 'drmp3_reset'
externals/dr_libs/dr_mp3.h:3765: Returning without writing to 'pMP3->pData'
externals/dr_libs/dr_mp3.h:3778: Returning from 'drmp3_reset'
externals/dr_libs/dr_mp3.h:3779: Returning without writing to 'pMP3->pData'
externals/dr_libs/dr_mp3.h:3950: Returning from 'drmp3_seek_to_start_of_stream'
externals/dr_libs/dr_mp3.h:3950: Taking false branch
externals/dr_libs/dr_mp3.h:3957: Loop condition is true. Entering loop body
externals/dr_libs/dr_mp3.h:3960: Calling 'drmp3_decode_next_frame_ex'
externals/dr_libs/dr_mp3.h:2795: Assuming field 'pData' is equal to NULL
externals/dr_libs/dr_mp3.h:2795: Left side of '&&' is false
externals/dr_libs/dr_mp3.h:2798: Calling 'drmp3_decode_next_frame_ex__callbacks'
externals/dr_libs/dr_mp3.h:2651: Field 'atEnd' is 0
externals/dr_libs/dr_mp3.h:2651: Taking false branch
externals/dr_libs/dr_mp3.h:2655: Loop condition is true. Entering loop body
externals/dr_libs/dr_mp3.h:2659: Field 'dataSize' is < DRMP3_MIN_DATA_CHUNK_SIZE
externals/dr_libs/dr_mp3.h:2659: Taking true branch
externals/dr_libs/dr_mp3.h:2663: Assuming pointer value is null
externals/dr_libs/dr_mp3.h:2663: Assuming field 'pData' is equal to NULL
externals/dr_libs/dr_mp3.h:2663: Taking false branch
externals/dr_libs/dr_mp3.h:2669: Assuming the condition is false
externals/dr_libs/dr_mp3.h:2669: Taking false branch
externals/dr_libs/dr_mp3.h:2684: Calling 'drmp3__on_read'
externals/dr_libs/dr_mp3.h:2593: Returning without writing to 'pMP3->pData'
externals/dr_libs/dr_mp3.h:2684: Returning from 'drmp3__on_read'
externals/dr_libs/dr_mp3.h:2685: Assuming 'bytesRead' is not equal to 0
externals/dr_libs/dr_mp3.h:2685: Taking false branch
externals/dr_libs/dr_mp3.h:2695: Assuming field 'dataSize' is <= INT_MAX
externals/dr_libs/dr_mp3.h:2695: Taking false branch
externals/dr_libs/dr_mp3.h:2703: Passing null pointer value via 2nd parameter 'mp3'
externals/dr_libs/dr_mp3.h:2703: Calling 'drmp3dec_decode_frame'
externals/dr_libs/dr_mp3.h:2275: Assuming 'mp3_bytes' is <= 4
externals/dr_libs/dr_mp3.h:2275: Left side of '&&' is false
externals/dr_libs/dr_mp3.h:2283: 'frame_size' is 0
externals/dr_libs/dr_mp3.h:2283: Taking true branch
externals/dr_libs/dr_mp3.h:2287: Assuming 'frame_size' is not equal to 0
externals/dr_libs/dr_mp3.h:2287: Left side of '||' is false
externals/dr_libs/dr_mp3.h:2287: Assuming the condition is false
externals/dr_libs/dr_mp3.h:2287: Taking false branch
externals/dr_libs/dr_mp3.h:2294: Null pointer value stored to 'hdr'
externals/dr_libs/dr_mp3.h:2295: Null pointer passed to 2nd parameter expecting 'nonnull'
externals/dr_libs/dr_mp3.h:734: expanded from macro 'DRMP3_COPY_MEMORY'
A possible fix would be to declare the attribute for gcc and clang as
or for c only
Obviously a macro such as
DRMP3_NONNULL(x)
could be added.Another fix would be to just early out from bad usage. Don't know if that's an option but the function has public (non-implmentation) visibility.