mirror of
https://github.com/claunia/flac.git
synced 2025-12-16 18:54:26 +00:00
fix bug in read callback where *bytes was not being set to 0 on end-of-stream condition
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user