input/InputStream: migrate from class Error to C++ exceptions

This commit is contained in:
Max Kellermann
2016-09-09 18:47:42 +02:00
parent 597e59f10d
commit 8c744efd56
64 changed files with 440 additions and 473 deletions

View File

@@ -21,10 +21,9 @@
#include "Aiff.hxx"
#include "input/InputStream.hxx"
#include "system/ByteOrder.hxx"
#include "Log.hxx"
#include "util/Error.hxx"
#include <limits>
#include <stdexcept>
#include <stdint.h>
#include <string.h>
@@ -45,33 +44,27 @@ aiff_seek_id3(InputStream &is)
{
/* seek to the beginning and read the AIFF header */
Error error;
if (!is.Rewind(error)) {
LogError(error, "Failed to seek");
return 0;
}
is.Rewind();
aiff_header header;
if (!is.ReadFull(&header, sizeof(header), IgnoreError()) ||
memcmp(header.id, "FORM", 4) != 0 ||
is.ReadFull(&header, sizeof(header));
if (memcmp(header.id, "FORM", 4) != 0 ||
(is.KnownSize() && FromLE32(header.size) > is.GetSize()) ||
(memcmp(header.format, "AIFF", 4) != 0 &&
memcmp(header.format, "AIFC", 4) != 0))
/* not a AIFF file */
return 0;
throw std::runtime_error("Not an AIFF file");
while (true) {
/* read the chunk header */
aiff_chunk_header chunk;
if (!is.ReadFull(&chunk, sizeof(chunk), IgnoreError()))
return 0;
is.ReadFull(&chunk, sizeof(chunk));
size_t size = FromBE32(chunk.size);
if (size > size_t(std::numeric_limits<int>::max()))
/* too dangerous, bail out: possible integer
underflow when casting to off_t */
return 0;
throw std::runtime_error("AIFF chunk is too large");
if (memcmp(chunk.id, "ID3 ", 4) == 0)
/* found it! */
@@ -81,7 +74,6 @@ aiff_seek_id3(InputStream &is)
/* pad byte */
++size;
if (!is.Skip(size, IgnoreError()))
return 0;
is.Skip(size);
}
}