Skip to content

Commit

Permalink
Zero-initialize SF_INFO structures everywhere else, too
Browse files Browse the repository at this point in the history
  • Loading branch information
musicinmybrain authored and evpobr committed May 1, 2021
1 parent 85a8f0b commit 3d91cc9
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const char *font_family = "DejaVu Sans Mono" ;
sf_count_t
sfx_mix_mono_read_double (SNDFILE * file, double * data, sf_count_t datalen)
{
SF_INFO info ;
SF_INFO info = {} ;

sf_command (file, SFC_GET_CURRENT_SF_INFO, &info, sizeof (info)) ;

Expand Down
2 changes: 1 addition & 1 deletion src/generate-chirp.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ generate_file (const char * filename, const PARAMS * params)
{
char buffer [1024] ;
SNDFILE * file ;
SF_INFO info ;
SF_INFO info = {} ;
double w0, w1 ;

memset (&info, 0, sizeof (info)) ;
Expand Down
2 changes: 1 addition & 1 deletion src/jackplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ int
main (int argc, char * argv [])
{ pthread_t thread_id ;
SNDFILE *sndfile ;
SF_INFO sfinfo ;
SF_INFO sfinfo = {} ;
const char * filename ;
jack_client_t *client ;
jack_status_t status = 0 ;
Expand Down
2 changes: 1 addition & 1 deletion src/mix-to-mono.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ int
main (int argc, char ** argv)
{
SNDFILE *infile, *outfile ;
SF_INFO sfinfo ;
SF_INFO sfinfo = {} ;

if (argc != 3)
usage_exit () ;
Expand Down
2 changes: 1 addition & 1 deletion src/spectrogram.c
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ static void
render_sndfile (RENDER * render)
{
SNDFILE *infile ;
SF_INFO info ;
SF_INFO info = {} ;

memset (&info, 0, sizeof (info)) ;

Expand Down
2 changes: 1 addition & 1 deletion src/waveform.c
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ static void
render_sndfile (RENDER * render)
{
SNDFILE *infile ;
SF_INFO info ;
SF_INFO info = {} ;
sf_count_t max_width ;

memset (&info, 0, sizeof (info)) ;
Expand Down

1 comment on commit 3d91cc9

@musicinmybrain
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It turns out that, for several of these (src/jackplay.c, src/mix-to-mono.c, src/spectrogram.c, src/waveform.c), the zero-initialization was already being done by a memset(), which I should have noticed but didn’t. After this commit, the SF_INFO is (theoretically; the compiler might optimize it out) zero-initialized twice.

To resolve the duplicate initializations, would you prefer a PR to revert the C99-style zero-initialization where memset() is already used, or to remove the memset()s and stick with the style in this commit?

Please sign in to comment.