From 827d44be321f7f371b7a4ae0e9f8446692ecda8b Mon Sep 17 00:00:00 2001 From: Dominic Clark Date: Thu, 3 Dec 2020 01:31:03 +0000 Subject: [PATCH] Ensure file opened successfully when loading sample (#5816) --- src/core/SampleBuffer.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/core/SampleBuffer.cpp b/src/core/SampleBuffer.cpp index 1872b920f..d057b8a91 100644 --- a/src/core/SampleBuffer.cpp +++ b/src/core/SampleBuffer.cpp @@ -196,11 +196,10 @@ void SampleBuffer::update( bool _keep_settings ) { // Use QFile to handle unicode file names on Windows QFile f(file); - f.open(QIODevice::ReadOnly); SNDFILE * snd_file; SF_INFO sf_info; sf_info.format = 0; - if( ( snd_file = sf_open_fd( f.handle(), SFM_READ, &sf_info, false ) ) != NULL ) + if (f.open(QIODevice::ReadOnly) && (snd_file = sf_open_fd(f.handle(), SFM_READ, &sf_info, false))) { f_cnt_t frames = sf_info.frames; int rate = sf_info.samplerate; @@ -396,8 +395,7 @@ f_cnt_t SampleBuffer::decodeSampleSF(QString _f, // Use QFile to handle unicode file names on Windows QFile f(_f); - f.open(QIODevice::ReadOnly); - if( ( snd_file = sf_open_fd( f.handle(), SFM_READ, &sf_info, false ) ) != NULL ) + if (f.open(QIODevice::ReadOnly) && (snd_file = sf_open_fd(f.handle(), SFM_READ, &sf_info, false))) { frames = sf_info.frames;