Skip to content

Commit

Permalink
warning fixes in flac loader
Browse files Browse the repository at this point in the history
  • Loading branch information
sezero committed Sep 5, 2019
1 parent 378f127 commit 0aba926
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 28 deletions.
27 changes: 11 additions & 16 deletions load_flac.c
Expand Up @@ -57,14 +57,13 @@ static FLAC__StreamDecoderReadStatus flac_read_load_cb(
// make sure there is something to be reading
if (*bytes > 0) {
FLAC_SDL_Data *data = (FLAC_SDL_Data *)client_data;
int nbytes = SDL_RWread (data->sdl_src, buffer, sizeof (FLAC__byte), *bytes);

*bytes = SDL_RWread (data->sdl_src, buffer, sizeof (FLAC__byte),
*bytes);

if(*bytes < 0) { // error in read
if(nbytes < 0) { // error in read
return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
}
else if(*bytes == 0) { // no data was read (EOF)
*bytes = nbytes;
if(nbytes == 0) { // no data was read (EOF)
return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
}
else { // data was read, continue
Expand Down Expand Up @@ -97,7 +96,6 @@ static FLAC__StreamDecoderTellStatus flac_tell_load_cb(
void *client_data)
{
FLAC_SDL_Data *data = (FLAC_SDL_Data *)client_data;

int pos = SDL_RWtell (data->sdl_src);

if (pos < 0) {
Expand All @@ -115,7 +113,6 @@ static FLAC__StreamDecoderLengthStatus flac_length_load_cb(
void *client_data)
{
FLAC_SDL_Data *data = (FLAC_SDL_Data *)client_data;

int pos = SDL_RWtell (data->sdl_src);
int length = SDL_RWseek (data->sdl_src, 0, RW_SEEK_END);

Expand All @@ -134,7 +131,6 @@ static FLAC__bool flac_eof_load_cb(const FLAC__StreamDecoder *decoder,
void *client_data)
{
FLAC_SDL_Data *data = (FLAC_SDL_Data *)client_data;

int pos = SDL_RWtell (data->sdl_src);
int end = SDL_RWseek (data->sdl_src, 0, RW_SEEK_END);

Expand Down Expand Up @@ -176,13 +172,12 @@ static FLAC__StreamDecoderWriteStatus flac_write_load_cb(
if (frame->header.number.sample_number == 0) {
*(data->sdl_audio_len) = data->sdl_spec->size;
data->sdl_audio_read = 0;
*(data->sdl_audio_buf) = SDL_malloc (*(data->sdl_audio_len));
*(data->sdl_audio_buf) = SDL_malloc (*(data->sdl_audio_len));

if (*(data->sdl_audio_buf) == NULL) {
SDL_SetError
("Unable to allocate memory to store the FLAC stream.");
return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
}
if (*(data->sdl_audio_buf) == NULL) {
SDL_SetError("Unable to allocate memory to store the FLAC stream.");
return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
}
}

buf = *(data->sdl_audio_buf);
Expand Down Expand Up @@ -336,7 +331,7 @@ SDL_AudioSpec *Mix_LoadFLAC_RW (SDL_RWops *src, int freesrc,
if (was_error)
spec = NULL;

return spec;
return spec;
}

#endif // FLAC_MUSIC
#endif /* FLAC_MUSIC */
19 changes: 7 additions & 12 deletions music_flac.c
Expand Up @@ -60,12 +60,13 @@ static FLAC__StreamDecoderReadStatus flac_read_music_cb(

// make sure there is something to be reading
if (*bytes > 0) {
*bytes = SDL_RWread (data->rwops, buffer, sizeof (FLAC__byte), *bytes);
int nbytes = SDL_RWread (data->rwops, buffer, sizeof (FLAC__byte), *bytes);

if (*bytes < 0) { // error in read
if (nbytes < 0) { // error in read
return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
}
else if (*bytes == 0 ) { // no data was read (EOF)
*bytes = nbytes;
if (nbytes == 0) { // no data was read (EOF)
return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
}
else { // data was read, continue
Expand Down Expand Up @@ -98,7 +99,6 @@ static FLAC__StreamDecoderTellStatus flac_tell_music_cb(
void *client_data )
{
FLAC_music *data = (FLAC_music*)client_data;

int pos = SDL_RWtell (data->rwops);

if (pos < 0) {
Expand All @@ -116,7 +116,6 @@ static FLAC__StreamDecoderLengthStatus flac_length_music_cb (
void *client_data)
{
FLAC_music *data = (FLAC_music*)client_data;

int pos = SDL_RWtell (data->rwops);
int length = SDL_RWseek (data->rwops, 0, RW_SEEK_END);

Expand All @@ -136,7 +135,6 @@ static FLAC__bool flac_eof_music_cb(
void *client_data )
{
FLAC_music *data = (FLAC_music*)client_data;

int pos = SDL_RWtell (data->rwops);
int end = SDL_RWseek (data->rwops, 0, RW_SEEK_END);

Expand Down Expand Up @@ -464,10 +462,9 @@ static void FLAC_getsome(FLAC_music *music)
}
cvt = &music->cvt;
if (music->section < 0) {

SDL_BuildAudioCVT (cvt, AUDIO_S16, (Uint8)music->flac_data.channels,
(int)music->flac_data.sample_rate, mixer.format,
mixer.channels, mixer.freq);
mixer.channels, mixer.freq);
if (cvt->buf) {
free (cvt->buf);
}
Expand Down Expand Up @@ -580,13 +577,11 @@ void FLAC_jump_to_time(FLAC_music *music, double time)
flac.FLAC__stream_decoder_flush (music->flac_decoder);
}

SDL_SetError
("Seeking of FLAC stream failed: libFLAC seek failed.");
SDL_SetError("Seeking of FLAC stream failed: libFLAC seek failed.");
}
}
else {
SDL_SetError
("Seeking of FLAC stream failed: FLAC decoder was NULL.");
SDL_SetError("Seeking of FLAC stream failed: FLAC decoder was NULL.");
}
}
else {
Expand Down

0 comments on commit 0aba926

Please sign in to comment.