add: if (buffer_size == 0) { decoder->error = SOUNDDECODER_EOF; return 0; }
context: uint32 SoundDecoder_Decode (TFB_SoundDecoder *decoder){	switch (decoder->type)	{		case SOUNDDECODER_WAV:		{			fprintf (stderr, "SoundDecoder_Decode(): unimplemented for wav\n");			break;		}		case SOUNDDECODER_MOD:		{			MODULE *mod = (MODULE *) decoder->data;			uint32 decoded_bytes;			Player_Start (mod);			if (!Player_Active())			{				if (decoder->looping)				{					fprintf (stderr, "SoundDecoder_Decode(): looping %s\n", decoder->filename);					Player_SetPosition (0);					Player_Start (mod);				}				else				{					fprintf (stderr, "SoundDecoder_Decode(): eof for %s\n", decoder->filename);					decoder->error = SOUNDDECODER_EOF;					return 0;				}			}			decoder->error = SOUNDDECODER_OK;			decoded_bytes = VC_WriteBytes (decoder->buffer, decoder->buffer_size);			/* MikMod produces output in machine byte-order			 * may need to do a word-swap 			 */			if (decoded_bytes > 0 &&					decoder_formats.big_endian != decoder_formats.want_big_endian &&					(decoder->format == decoder_formats.stereo16 ||					decoder->format == decoder_formats.mono16))			{				SoundDecoder_SwapWords (						decoder->buffer, decoded_bytes);			}			return decoded_bytes;		}		case SOUNDDECODER_OGG:		{			OggVorbis_File *vf = (OggVorbis_File *) decoder->data;			uint32 decoded_bytes = 0, count = 0;			long rc;			int bitstream;			uint32 max_bytes, buffer_size, close_on_done = 0;			char *buffer = (char *) decoder->buffer;			if (! decoder->looping)			{				if (decoder->format == decoder_formats.stereo16)					max_bytes = decoder->end_sample * 4;				else					max_bytes = decoder->end_sample * 2;				if (max_bytes - decoder->pos < decoder->buffer_size)				{					buffer_size = max_bytes - decoder->pos;					close_on_done = 1;				}				else				{					buffer_size = decoder->buffer_size;				}			}			else				buffer_size = decoder->buffer_size;			while (decoded_bytes < buffer_size)			{					/* Produce output in requested byte-order */				rc = ov_read (vf, &buffer[decoded_bytes],						buffer_size - decoded_bytes,						decoder_formats.want_big_endian, 2, 1, &bitstream);				if (rc < 0)				{					decoder->error = SOUNDDECODER_ERROR;					fprintf (stderr, "SoundDecoder_Decode(): error decoding %s, code %ld\n", decoder->filename, rc);					return decoded_bytes;				}				if (rc == 0 || (close_on_done && buffer_size == (decoded_bytes + rc)))				{					if (close_on_done)					{						decoded_bytes += rc;					}					if (decoder->looping)					{						SoundDecoder_Rewind (decoder);						if (decoder->error)						{							fprintf (stderr, "SoundDecoder_Decode(): tried to loop %s but couldn't rewind, error code %d\n", decoder->filename, decoder->error);						}						else						{							fprintf (stderr, "SoundDecoder_Decode(): looping %s\n", decoder->filename);							count++;							continue;						}					}					else						decoder->pos += decoded_bytes;					fprintf (stderr, "SoundDecoder_Decode(): eof for %s\n", decoder->filename);					decoder->error = SOUNDDECODER_EOF;					return decoded_bytes;				}				decoded_bytes += rc;				//fprintf (stderr, "iter %d rc %d decoded_bytes %d remaining %d\n", count, rc, decoded_bytes, decoder->buffer_size - decoded_bytes);				count++;			}			decoder->pos += decoded_bytes;			decoder->error = SOUNDDECODER_OK;			//fprintf (stderr, "SoundDecoder_Decode(): decoded %d bytes from %s\n", decoded_bytes, decoder->filename);			return decoded_bytes;		}		case SOUNDDECODER_NULL:		{			uint32 max_bytes;			max_bytes = decoder->end_sample * 2;			if (max_bytes - decoder->pos <= decoder->buffer_size)				{					uint32 bufsize = max_bytes - decoder->pos;					decoder->pos = max_bytes;					decoder->error = SOUNDDECODER_EOF;					return (bufsize);				}				else				{					decoder->pos += decoder->buffer_size;					decoder->error = SOUNDDECODER_OK;					return (decoder->buffer_size);				}		}		case SOUNDDECODER_BUF:			decoder->buffer = (char *)decoder->data + decoder->pos;			decoder->error = SOUNDDECODER_EOF;			return (decoder->buffer_size - decoder->pos);		default:		{			fprintf (stderr, "SoundDecoder_Decode(): unknown type %d\n", decoder->type);			break;		}	}	decoder->error = SOUNDDECODER_ERROR;	return 0;}