fix bug in read callback where *bytes was not being set to 0 on end-of-stream condition

This commit is contained in:
Josh Coalson
2003-12-30 03:33:43 +00:00
parent 9b07b61fba
commit 06c9c5327b
3 changed files with 20 additions and 17 deletions

View File

@@ -137,6 +137,7 @@ static FLAC__bool generate_file_()
static FLAC__StreamDecoderReadStatus stream_decoder_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data)
{
stream_decoder_client_data_struct *dcd = (stream_decoder_client_data_struct*)client_data;
const unsigned requested_bytes = *bytes;
(void)decoder;
@@ -148,18 +149,19 @@ static FLAC__StreamDecoderReadStatus stream_decoder_read_callback_(const FLAC__S
if(dcd->error_occurred)
return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
if(feof(dcd->file))
if(feof(dcd->file)) {
*bytes = 0;
return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
else if(*bytes > 0) {
unsigned bytes_read = fread(buffer, 1, *bytes, dcd->file);
if(bytes_read == 0) {
}
else if(requested_bytes > 0) {
*bytes = fread(buffer, 1, requested_bytes, dcd->file);
if(*bytes == 0) {
if(feof(dcd->file))
return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
else
return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
}
else {
*bytes = bytes_read;
return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
}
}