Skip to content

Commit 41b6b0c

Browse files
committed
Prevent NPE if output is not defined
1 parent d00adcb commit 41b6b0c

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/AACDecoderHelix.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,11 @@ class AACDecoderHelix : public CommonHelix {
139139
infoCallback(info, p_caller_ref);
140140
}
141141
#if defined(ARDUINO) || defined(HELIX_PRINT)
142-
out->write((uint8_t *)pcm_buffer.data(), info.outputSamps * sampleSize);
142+
if (out != nullptr){
143+
size_t to_write = info.outputSamps * sampleSize;
144+
size_t written = out->write((uint8_t *)pcm_buffer.data(), to_write);
145+
assert(written == to_write);
146+
}
143147
#endif
144148
}
145149
aacFrameInfo = info;

src/MP3DecoderHelix.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,13 @@ class MP3DecoderHelix : public CommonHelix {
147147
infoCallback(info, p_caller_ref);
148148
}
149149
#if defined(ARDUINO) || defined(HELIX_PRINT)
150-
int sampleSize = info.bitsPerSample / 8;
151-
int toWrite = info.outputSamps * sampleSize;
152-
int written = out->write((uint8_t *)pcm_buffer.data(), toWrite);
153-
// assume blocking write
154-
assert(written == toWrite);
150+
if (out != nullptr){
151+
int sampleSize = info.bitsPerSample / 8;
152+
int toWrite = info.outputSamps * sampleSize;
153+
int written = out->write((uint8_t *)pcm_buffer.data(), toWrite);
154+
// assume blocking write
155+
assert(written == toWrite);
156+
}
155157
#endif
156158
}
157159
mp3FrameInfo = info;

0 commit comments

Comments
 (0)