From bc2d946ba6a321281454c4b1627a220e1e145990 Mon Sep 17 00:00:00 2001 From: Carsten Teibes Date: Wed, 28 Jun 2017 16:53:42 +0200 Subject: [PATCH] Fix flawed conditionals --- src/audio_decoder.cpp | 8 ++++---- src/audio_generic.cpp | 2 +- src/audio_sdl_mixer.cpp | 2 +- src/decoder_fmmidi.cpp | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/audio_decoder.cpp b/src/audio_decoder.cpp index 1ddc469903..c00ebce64c 100644 --- a/src/audio_decoder.cpp +++ b/src/audio_decoder.cpp @@ -130,7 +130,7 @@ const char wma_magic[] = { (char)0x30, (char)0x26, (char)0xB2, (char)0x75 }; std::unique_ptr AudioDecoder::Create(FILE* file, const std::string& filename) { char magic[4] = { 0 }; - if (fread(magic, 4, 1, file) != 4) + if (fread(magic, 4, 1, file) != 1) return nullptr; fseek(file, 0, SEEK_SET); @@ -176,7 +176,7 @@ std::unique_ptr AudioDecoder::Create(FILE* file, const std::string if (!strncmp(magic, "OggS", 4)) { // OGG #ifdef HAVE_OPUS fseek(file, 28, SEEK_SET); - if (fread(magic, 4, 1, file) != 4) + if (fread(magic, 4, 1, file) != 1) return nullptr; fseek(file, 0, SEEK_SET); if (!strncmp(magic, "Opus", 4)) { @@ -190,7 +190,7 @@ std::unique_ptr AudioDecoder::Create(FILE* file, const std::string #if defined(HAVE_TREMOR) || defined(HAVE_OGGVORBIS) fseek(file, 29, SEEK_SET); - if (fread(magic, 4, 1, file) != 4) + if (fread(magic, 4, 1, file) != 1) return nullptr; fseek(file, 0, SEEK_SET); @@ -209,7 +209,7 @@ std::unique_ptr AudioDecoder::Create(FILE* file, const std::string if (!strncmp(magic, "RIFF", 4)) { fseek(file, 20, SEEK_SET); uint16_t raw_enc; - if (fread(&raw_enc, 2, 1, file) != 2) + if (fread(&raw_enc, 2, 1, file) != 1) return nullptr; Utils::SwapByteOrder(raw_enc); fseek(file, 0, SEEK_SET); diff --git a/src/audio_generic.cpp b/src/audio_generic.cpp index b1df3ff72e..69148bc290 100644 --- a/src/audio_generic.cpp +++ b/src/audio_generic.cpp @@ -228,7 +228,7 @@ void GenericAudio::Decode(uint8_t* output_buffer, int buffer_length) { float total_volume = 0; int samples_per_frame = buffer_length / output_format.channels / 2; - assert(buffer_length < 0); + assert(buffer_length > 0); if (sample_buffer.size() != (size_t)buffer_length) { sample_buffer.resize(buffer_length); diff --git a/src/audio_sdl_mixer.cpp b/src/audio_sdl_mixer.cpp index a8d6433d4b..1aa4125781 100644 --- a/src/audio_sdl_mixer.cpp +++ b/src/audio_sdl_mixer.cpp @@ -288,7 +288,7 @@ void SdlMixerAudio::BGM_Play(std::string const& file, int volume, int pitch, int Output::Warning("Music not readable: %s", FileFinder::GetPathInsideGamePath(file).c_str()); return; } - if (fread(magic, 4, 1, filehandle) != 4) + if (fread(magic, 4, 1, filehandle) != 1) return; fseek(filehandle, 0, SEEK_SET); if (!strncmp(magic, "MThd", 4)) { diff --git a/src/decoder_fmmidi.cpp b/src/decoder_fmmidi.cpp index cffcf97e61..9532551da5 100644 --- a/src/decoder_fmmidi.cpp +++ b/src/decoder_fmmidi.cpp @@ -57,7 +57,7 @@ bool FmMidiDecoder::Open(FILE* file) { fseek(file, 0, SEEK_END); file_buffer.resize(ftell(file) - old_pos); fseek(file, old_pos, SEEK_SET); - size_t bytes_read = fread(file_buffer.data(), file_buffer.size(), 1, file); + size_t bytes_read = fread(file_buffer.data(), 1, file_buffer.size(), file); if ((bytes_read != file_buffer.size()) || (!seq->load(this, read_func))) { error_message = "FM Midi: Error reading file";