libgme / game-music-emu

Blargg's video game music emulation library, which allows audio applications to easily add playback support for the music of many classic video game consoles.
GNU Lesser General Public License v2.1
59 stars 12 forks source link

NULL being fed to memset() #63

Closed sezero closed 9 months ago

sezero commented 9 months ago

I get the following warning from gcc: (curious that it doesn't show up in CI logs?)

/tmp/game-music-emu/gme/Ym2612_Nuked.cpp: In member function ‘void Ym2612_Nuked_Emu::reset()’:
/tmp/game-music-emu/gme/Ym2612_Nuked.cpp:1413:11: warning: argument 1 null where non-null expected [-Wnonnull]
     memset(chip, 0, sizeof(ym3438_t));
     ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /tmp/game-music-emu/gme/Ym2612_Nuked.cpp:37:0:
/usr/include/string.h:60:14: note: in a call to function ‘void* memset(void*, int, size_t)’ declared here
 extern void *memset (void *__s, int __c, size_t __n) __THROW __nonnull ((1));
              ^~~~~~

I think the condition here is a typo: Is the following patch correct? If it is, I can send a PR.

diff --git a/gme/Ym2612_Nuked.cpp b/gme/Ym2612_Nuked.cpp
index c408bd4..23a60c2 100644
--- a/gme/Ym2612_Nuked.cpp
+++ b/gme/Ym2612_Nuked.cpp
@@ -1839,7 +1839,7 @@ const char *Ym2612_Nuked_Emu::set_rate(double sample_rate, double clock_rate)
 void Ym2612_Nuked_Emu::reset()
 {
    Ym2612_NukedImpl::ym3438_t *chip_r = reinterpret_cast<Ym2612_NukedImpl::ym3438_t*>(impl);
-   if ( !chip_r ) Ym2612_NukedImpl::OPN2_Reset( chip_r, static_cast<Bit32u>(prev_sample_rate), static_cast<Bit32u>(prev_clock_rate) );
+   if ( chip_r ) Ym2612_NukedImpl::OPN2_Reset( chip_r, static_cast<Bit32u>(prev_sample_rate), static_cast<Bit32u>(prev_clock_rate) );
 }

 void Ym2612_Nuked_Emu::mute_voices(int mask)
sezero commented 9 months ago

No matter how I look at it, that's a typo. I went ahead and created https://github.com/libgme/game-music-emu/pull/64 -- please review and test.