Commit 2e64afca authored by Max Kellermann's avatar Max Kellermann

decoder/modplug: check InputStream::KnownSize()

parent 51cda0be
...@@ -54,7 +54,15 @@ modplug_decoder_init(const config_param &param) ...@@ -54,7 +54,15 @@ modplug_decoder_init(const config_param &param)
static WritableBuffer<uint8_t> static WritableBuffer<uint8_t>
mod_loadfile(Decoder *decoder, InputStream &is) mod_loadfile(Decoder *decoder, InputStream &is)
{ {
const InputStream::offset_type size = is.GetSize(); //known/unknown size, preallocate array, lets read in chunks
const bool is_stream = !is.KnownSize();
WritableBuffer<uint8_t> buffer;
if (is_stream)
buffer.size = MODPLUG_PREALLOC_BLOCK;
else {
const auto size = is.GetSize();
if (size == 0) { if (size == 0) {
LogWarning(modplug_domain, "file is empty"); LogWarning(modplug_domain, "file is empty");
...@@ -66,12 +74,9 @@ mod_loadfile(Decoder *decoder, InputStream &is) ...@@ -66,12 +74,9 @@ mod_loadfile(Decoder *decoder, InputStream &is)
return { nullptr, 0 }; return { nullptr, 0 };
} }
//known/unknown size, preallocate array, lets read in chunks buffer.size = size;
}
const bool is_stream = size < 0;
WritableBuffer<uint8_t> buffer;
buffer.size = is_stream ? MODPLUG_PREALLOC_BLOCK : size;
buffer.data = new uint8_t[buffer.size]; buffer.data = new uint8_t[buffer.size];
uint8_t *const end = buffer.end(); uint8_t *const end = buffer.end();
......
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