Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test unions in ply_xwave #2056

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 12 additions & 20 deletions src/m4a.c
Original file line number Diff line number Diff line change
Expand Up @@ -1523,18 +1523,14 @@ void ply_xxx(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *track)

void ply_xwave(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *track)
{
u32 wav;
union { u8 *a; u8 d[4]; } u;

#ifdef UBFIX
wav = 0;
#endif

READ_XCMD_BYTE(wav, 0) // UB: uninitialized variable
READ_XCMD_BYTE(wav, 1)
READ_XCMD_BYTE(wav, 2)
READ_XCMD_BYTE(wav, 3)
u.d[0] = *(track->cmdPtr + 0);
u.d[1] = *(track->cmdPtr + 1);
u.d[2] = *(track->cmdPtr + 2);
u.d[3] = *(track->cmdPtr + 3);

track->tone.wav = (struct WaveData *)wav;
track->tone.wav = (struct WaveData *)u.a;
track->cmdPtr += 4;
}

Expand Down Expand Up @@ -1618,18 +1614,14 @@ void ply_xcmd_0C(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *tra

void ply_xcmd_0D(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *track)
{
u32 unk;

#ifdef UBFIX
unk = 0;
#endif
union { u32 a; u8 d[4]; } u;

READ_XCMD_BYTE(unk, 0) // UB: uninitialized variable
READ_XCMD_BYTE(unk, 1)
READ_XCMD_BYTE(unk, 2)
READ_XCMD_BYTE(unk, 3)
u.d[0] = *(track->cmdPtr + 0);
u.d[1] = *(track->cmdPtr + 1);
u.d[2] = *(track->cmdPtr + 2);
u.d[3] = *(track->cmdPtr + 3);

track->unk_3C = unk;
track->unk_3C = u.a;
track->cmdPtr += 4;
}

Expand Down