LIJI32 / SameBoy

Game Boy and Game Boy Color emulator written in C
https://sameboy.github.io/
Other
1.58k stars 206 forks source link

Fix potential compiler warning on questionable code path #607

Closed Morilli closed 2 months ago

Morilli commented 2 months ago

This line displayed a compiler warning to me:

.../Core/gb.c:1708:27: warning: arithmetic on a null pointer treated as a cast from integer to pointer is a GNU extension [-Wgnu-null-pointer-arithmetic]
 1708 |     memset(gb, 0, (size_t)GB_GET_SECTION(NULL, unsaved));
      |                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.../Core/save_state.h:24:59: note: expanded from macro 'GB_GET_SECTION'
   24 | #define GB_GET_SECTION(gb, name) (void *)((uint8_t *)(gb) + GB_SECTION_OFFSET(name))
      |                                           ~~~~~~~~~~~~~~~ ^

The warning probably only surfaces with specific compiler/warning combinations used, but this line of code seems questionable anyways considering what it's actually trying to do, so I've simplified it and fixes the compiler warning at the same time.

LIJI32 commented 2 months ago

I probably wrote this before I added the GB_SECTION_OFFSET macro. Thanks!