diff options
| author | Ray <[email protected]> | 2023-02-23 18:08:15 +0100 |
|---|---|---|
| committer | Ray <[email protected]> | 2023-02-23 18:08:15 +0100 |
| commit | d5a31168ce768ef9c1e11fe4734285770a33aba4 (patch) | |
| tree | be8dd3c0577d90daf04316adbc0736e6502e48e9 /src | |
| parent | d652b95fbfc06b7a996386c9d212e9fe2d669ed8 (diff) | |
| download | raylib-d5a31168ce768ef9c1e11fe4734285770a33aba4.tar.gz raylib-d5a31168ce768ef9c1e11fe4734285770a33aba4.zip | |
REVIEWED: Data validation
Diffstat (limited to 'src')
| -rw-r--r-- | src/raudio.c | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/src/raudio.c b/src/raudio.c index 5f533215..04386167 100644 --- a/src/raudio.c +++ b/src/raudio.c @@ -868,7 +868,11 @@ Wave LoadWaveFromMemory(const char *fileType, const unsigned char *fileData, int // Checks if wave data is ready bool IsWaveReady(Wave wave) { - return wave.data != NULL; + return ((wave.data != NULL) && // Validate wave data available + (wave.frameCount > 0) && // Validate frame count + (wave.sampleRate > 0) && // Validate sample rate is supported + (wave.sampleSize > 0) && // Validate sample size is supported + (wave.channels > 0)); // Validate number of channels supported } // Load sound from file @@ -930,7 +934,11 @@ Sound LoadSoundFromWave(Wave wave) // Checks if a sound is ready bool IsSoundReady(Sound sound) { - return sound.stream.buffer != NULL; + return ((sound.frameCount > 0) && // Validate frame count + (sound.stream.buffer != NULL) && // Validate stream buffer + (sound.stream.sampleRate > 0) && // Validate sample rate is supported + (sound.stream.sampleSize > 0) && // Validate sample size is supported + (sound.stream.channels > 0)); // Validate number of channels supported } // Unload wave data @@ -1722,7 +1730,11 @@ Music LoadMusicStreamFromMemory(const char *fileType, const unsigned char *data, // Checks if a music stream is ready bool IsMusicReady(Music music) { - return music.ctxData != NULL; + return ((music.ctxData != NULL) && // Validate context loaded + (music.frameCount > 0) && // Validate audio frame count + (music.stream.sampleRate > 0) && // Validate sample rate is supported + (music.stream.sampleSize > 0) && // Validate sample size is supported + (music.stream.channels > 0)); // Validate number of channels supported } // Unload music stream @@ -2097,7 +2109,10 @@ AudioStream LoadAudioStream(unsigned int sampleRate, unsigned int sampleSize, un // Checks if an audio stream is ready RLAPI bool IsAudioStreamReady(AudioStream stream) { - return stream.buffer != NULL; + return ((stream.buffer != NULL) && // Validate stream buffer + (stream.sampleRate > 0) && // Validate sample rate is supported + (stream.sampleSize > 0) && // Validate sample size is supported + (stream.channels > 0)); // Validate number of channels supported } // Unload audio stream and free memory |
