We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 4746

Summary: add SDL_zeroa
Product: SDL Reporter: Ozkan Sezer <sezeroz>
Component: *don't know*Assignee: Ryan C. Gordon <icculus>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2    
Version: HG 2.0   
Hardware: All   
OS: All   
Attachments: SDL_zeroa patch
SDL_zeroa patch

Description Ozkan Sezer 2019-07-30 21:56:00 UTC
We currently have code like below which seems wrong:
  type_t array[2];
  SDL_zero(array);

From watcom, I get the following warnings in c++ mode:

src/audio/SDL_audio.c(951): Warning! W007: col(26) '&array' may not produce intended result
src/audio/SDL_audio.c(1611): Warning! W007: col(26) '&array' may not produce intended result
  SDL_zero(open_devices);

src/audio/SDL_audiocvt.c(918): Warning! W007: col(26) '&array' may not produce intended result
  SDL_zero(cvt->filters);

src/audio/SDL_wave.c(650): Warning! W007: col(20) '&array' may not produce intended result
  SDL_zero(cstate);

src/joystick/SDL_gamecontroller.c(645): Warning! W007: col(26) '&array' may not produce intended result
src/joystick/SDL_gamecontroller.c(646): Warning! W007: col(30) '&array' may not produce intended result
  SDL_zero(szGameButton);
  SDL_zero(szJoystickButton);

src/joystick/SDL_gamecontroller.c(658): Warning! W007: col(34) '&array' may not produce intended result
src/joystick/SDL_gamecontroller.c(659): Warning! W007: col(38) '&array' may not produce intended result
  SDL_zero(szGameButton);
  SDL_zero(szJoystickButton);


I suggest adding a new SDL_zeroa macro like below, and changing
the relevant statements to it:
#define SDL_zeroa(x) SDL_memset((x), 0, sizeof((x)))
-  SDL_zero(array);
+  SDL_zeroa(array);

A patch is attached for it.
After applying it, Watcom's binary output is identical for me.


Comments?  OK?
Comment 1 Ozkan Sezer 2019-07-30 21:56:46 UTC
Created attachment 3909 [details]
SDL_zeroa patch
Comment 2 Ozkan Sezer 2019-07-30 22:15:00 UTC
Created attachment 3910 [details]
SDL_zeroa patch

(Attaching the correct patch file this time.)
Comment 3 Ryan C. Gordon 2019-07-30 22:18:22 UTC
This looks good to me, go ahead and apply it.

--ryan.
Comment 4 Ozkan Sezer 2019-07-30 22:23:04 UTC
Applied:  https://hg.libsdl.org/SDL/rev/0262d439e9c6