Commit bcba79ce authored by Stefan Westerfeld's avatar Stefan Westerfeld

Avoid calling fwrite() with nullptr (which is undefined behaviour).

Signed-off-by: Stefan Westerfeld's avatarStefan Westerfeld <stefan@space.twc.de>
parent 4e6c300b
...@@ -88,6 +88,9 @@ RawOutputStream::write_frames (const vector<float>& samples) ...@@ -88,6 +88,9 @@ RawOutputStream::write_frames (const vector<float>& samples)
{ {
assert (m_state == State::OPEN); assert (m_state == State::OPEN);
if (samples.empty())
return Error::Code::NONE;
vector<unsigned char> bytes; vector<unsigned char> bytes;
m_raw_converter->to_raw (samples, bytes); m_raw_converter->to_raw (samples, bytes);
......
...@@ -132,11 +132,14 @@ StdoutWavOutputStream::open (int n_channels, int sample_rate, int bit_depth, siz ...@@ -132,11 +132,14 @@ StdoutWavOutputStream::open (int n_channels, int sample_rate, int bit_depth, siz
Error Error
StdoutWavOutputStream::write_frames (const vector<float>& samples) StdoutWavOutputStream::write_frames (const vector<float>& samples)
{ {
if (samples.empty())
return Error::Code::NONE;
vector<unsigned char> output_bytes; vector<unsigned char> output_bytes;
m_raw_converter->to_raw (samples, output_bytes); m_raw_converter->to_raw (samples, output_bytes);
fwrite (output_bytes.data(), 1, output_bytes.size(), stdout); fwrite (&output_bytes[0], 1, output_bytes.size(), stdout);
if (ferror (stdout)) if (ferror (stdout))
return Error ("write sample data failed"); return Error ("write sample data failed");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment