From 1b0fef3d25ed94518f4f6b1914a7d7e71aae80c5 Mon Sep 17 00:00:00 2001 From: trialuser02 Date: Sun, 6 Jan 2019 16:10:03 +0000 Subject: added realloc result checking git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@8589 90c681e8-e032-0410-971d-27865f9a5e38 --- src/plugins/Effect/crossfade/crossfadeplugin.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'src/plugins/Effect') diff --git a/src/plugins/Effect/crossfade/crossfadeplugin.cpp b/src/plugins/Effect/crossfade/crossfadeplugin.cpp index 29e76bd86..424bd5037 100644 --- a/src/plugins/Effect/crossfade/crossfadeplugin.cpp +++ b/src/plugins/Effect/crossfade/crossfadeplugin.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2009-2015 by Ilya Kotov * + * Copyright (C) 2009-2019 by Ilya Kotov * * Copyright (C) 2009 by Sebastian Pipping * * * * This program is free software; you can redistribute it and/or modify * @@ -65,11 +65,23 @@ void CrossfadePlugin::applyEffect(Buffer *b) if(m_buffer_at + b->samples > m_buffer_size) { m_buffer_size = m_buffer_at + b->samples; + float *tmp = m_buffer; m_buffer = (float *)realloc(m_buffer, m_buffer_size * sizeof(float)); + if(!m_buffer) + { + qWarning("CrossfadePlugin: unable to allocate %zu bytes", m_buffer_size); + m_buffer_size = 0; + if(tmp) + free(tmp); + } + } + + if(m_buffer) + { + memcpy(m_buffer + m_buffer_at, b->data, b->samples * sizeof(float)); + m_buffer_at += b->samples; + b->samples = 0; } - memcpy(m_buffer + m_buffer_at, b->data, b->samples * sizeof(float)); - m_buffer_at += b->samples; - b->samples = 0; } else if(m_buffer_at > 0) m_state = PROCESSING; -- cgit v1.2.3-13-gbd6f