Commit 06c9c532 authored by Josh Coalson's avatar Josh Coalson
Browse files

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

parent 9b07b61f
......@@ -706,16 +706,16 @@ FLAC__StreamDecoderReadStatus read_callback_(const FLAC__StreamDecoder *decoder,
FLAC__SeekableStreamDecoder *seekable_stream_decoder = (FLAC__SeekableStreamDecoder *)client_data;
(void)decoder;
if(seekable_stream_decoder->private_->eof_callback(seekable_stream_decoder, seekable_stream_decoder->private_->client_data)) {
*bytes = 0;
seekable_stream_decoder->protected_->state = FLAC__SEEKABLE_STREAM_DECODER_END_OF_STREAM;
return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
}
else if(*bytes > 0) {
unsigned bytes_read = *bytes;
if(seekable_stream_decoder->private_->read_callback(seekable_stream_decoder, buffer, &bytes_read, seekable_stream_decoder->private_->client_data) != FLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_OK) {
if(seekable_stream_decoder->private_->read_callback(seekable_stream_decoder, buffer, bytes, seekable_stream_decoder->private_->client_data) != FLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_OK) {
seekable_stream_decoder->protected_->state = FLAC__SEEKABLE_STREAM_DECODER_READ_ERROR;
return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
}
if(bytes_read == 0) {
if(*bytes == 0) {
if(seekable_stream_decoder->private_->eof_callback(seekable_stream_decoder, seekable_stream_decoder->private_->client_data)) {
seekable_stream_decoder->protected_->state = FLAC__SEEKABLE_STREAM_DECODER_END_OF_STREAM;
return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
......@@ -724,7 +724,6 @@ FLAC__StreamDecoderReadStatus read_callback_(const FLAC__StreamDecoder *decoder,
return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
}
else {
*bytes = bytes_read;
return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
}
}
......
......@@ -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;
}
}
......
......@@ -149,6 +149,7 @@ static FLAC__bool generate_file_()
static FLAC__StreamDecoderReadStatus stream_decoder_read_callback_(const OggFLAC__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;
......@@ -160,18 +161,19 @@ static FLAC__StreamDecoderReadStatus stream_decoder_read_callback_(const OggFLAC
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;
}
}
......@@ -805,9 +807,9 @@ static FLAC__SeekableStreamDecoderReadStatus seekable_stream_decoder_read_callba
(void)decoder;
switch(stream_decoder_read_callback_(0, buffer, bytes, client_data)) {
case FLAC__STREAM_DECODER_READ_STATUS_CONTINUE:
case FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM:
return FLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_OK;
case FLAC__STREAM_DECODER_READ_STATUS_ABORT:
case FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM:
return FLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_ERROR;
default:
FLAC__ASSERT(0);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment