src/sndfile.c : Fix sfinfo.frames file on SFM_WRITE.

When opening a file in SFM_WRITE mode where the output is a pipe,
the sfinfo.frames value was coming back with strange values. The
fix is simply to make sure it get set to zero.

Closes: https://github.com/erikd/libsndfile/issues/77
This commit is contained in:
Erik de Castro Lopo 2014-10-17 21:25:32 +11:00
parent bc012ab732
commit 19e12f5641
2 changed files with 17 additions and 8 deletions

View File

@ -2682,11 +2682,6 @@ psf_open_file (SF_PRIVATE *psf, SF_INFO *sfinfo)
goto error_exit ;
} ;
/* Zero out these fields. */
sfinfo->frames = 0 ;
sfinfo->sections = 0 ;
sfinfo->seekable = 0 ;
if (psf->file.mode == SFM_READ)
{ if ((SF_CONTAINER (sfinfo->format)) == SF_FORMAT_RAW)
{ if (sf_format_check (sfinfo) == 0)
@ -2990,6 +2985,14 @@ psf_open_file (SF_PRIVATE *psf, SF_INFO *sfinfo)
memcpy (sfinfo, &psf->sf, sizeof (SF_INFO)) ;
if (psf->file.mode == SFM_WRITE)
{ /* Zero out these fields. */
sfinfo->frames = 0 ;
} ;
sfinfo->sections = 0 ;
sfinfo->seekable = 0 ;
return (SNDFILE *) psf ;
error_exit :

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2001-2012 Erik de Castro Lopo <erikd@mega-nerd.com>
** Copyright (C) 2001-2014 Erik de Castro Lopo <erikd@mega-nerd.com>
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
@ -138,8 +138,14 @@ stdout_test (int typemajor, int count)
data [k] = PIPE_INDEX (k) ;
if ((file = sf_open ("-", SFM_WRITE, &sfinfo)) == NULL)
{ fprintf (stderr, "sf_open_write failed with error : ") ;
fprintf (stderr, "%s\n", sf_strerror (NULL)) ;
{ fprintf (stderr, "%s % d: sf_open_write failed with error : %s\n",
__func__, __LINE__, sf_strerror (NULL)) ;
exit (1) ;
} ;
if (sfinfo.frames != 0)
{ fprintf (stderr, "%s % d: Frames is %d (should be 0).\n",
__func__, __LINE__, (int) sfinfo.frames) ;
exit (1) ;
} ;