aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/kyra/script.cpp26
-rw-r--r--engines/kyra/script_tim.cpp12
2 files changed, 21 insertions, 17 deletions
diff --git a/engines/kyra/script.cpp b/engines/kyra/script.cpp
index 6d69b6bffb..cbb0ba6eb6 100644
--- a/engines/kyra/script.cpp
+++ b/engines/kyra/script.cpp
@@ -83,13 +83,15 @@ bool EMCInterpreter::load(const char *filename, EMCData *scriptData, const Commo
case MKID_BE('TEXT'):
scriptData->text = new byte[chunk->size];
assert(scriptData->text);
- chunk->read(scriptData->text, chunk->size);
+ if (chunk->read(scriptData->text, chunk->size) != chunk->size)
+ error("Couldn't read TEXT chunk from file '%s'", filename);
break;
case MKID_BE('ORDR'):
scriptData->ordr = new uint16[chunk->size >> 1];
assert(scriptData->ordr);
- chunk->read(scriptData->ordr, chunk->size);
+ if (chunk->read(scriptData->ordr, chunk->size) != chunk->size)
+ error("Couldn't read ORDR chunk from file '%s'", filename);
for (int i = (chunk->size >> 1) - 1; i >= 0; --i)
scriptData->ordr[i] = READ_BE_UINT16(&scriptData->ordr[i]);
@@ -98,7 +100,8 @@ bool EMCInterpreter::load(const char *filename, EMCData *scriptData, const Commo
case MKID_BE('DATA'):
scriptData->data = new uint16[chunk->size >> 1];
assert(scriptData->data);
- chunk->read(scriptData->data, chunk->size);
+ if (chunk->read(scriptData->data, chunk->size) != chunk->size)
+ error("Couldn't read DATA chunk from file '%s'", filename);
for (int i = (chunk->size >> 1) - 1; i >= 0; --i)
scriptData->data[i] = READ_BE_UINT16(&scriptData->data[i]);
@@ -110,17 +113,14 @@ bool EMCInterpreter::load(const char *filename, EMCData *scriptData, const Commo
}
}
- if (!scriptData->ordr) {
- unload(scriptData);
- error("Couldn't read ORDR chunk from file: '%s'", filename);
- return false;
- }
+ if (!scriptData->ordr)
+ error("No ORDR chunk found in file: '%s'", filename);
- if (!scriptData->data) {
- unload(scriptData);
- error("Couldn't read DATA chunk from file: '%s'", filename);
- return false;
- }
+ if (!scriptData->data)
+ error("No DATA chunk found in file: '%s'", filename);
+
+ if (stream->err())
+ error("Read error while parsing file '%s", filename);
delete stream;
diff --git a/engines/kyra/script_tim.cpp b/engines/kyra/script_tim.cpp
index e52a36c3b5..4d4006f5b9 100644
--- a/engines/kyra/script_tim.cpp
+++ b/engines/kyra/script_tim.cpp
@@ -149,7 +149,8 @@ TIM *TIMInterpreter::load(const char *filename, const Common::Array<const TIMOpc
avtlChunkSize = chunk->size >> 1;
tim->avtl = new uint16[avtlChunkSize];
assert(tim->avtl);
- chunk->read(tim->avtl, chunk->size);
+ if (chunk->read(tim->avtl, chunk->size) != chunk->size)
+ error("Couldn't read AVTL chunk from file '%s'", filename);
for (int i = avtlChunkSize - 1; i >= 0; --i)
tim->avtl[i] = READ_LE_UINT16(&tim->avtl[i]);
@@ -161,10 +162,13 @@ TIM *TIMInterpreter::load(const char *filename, const Common::Array<const TIMOpc
}
}
- delete stream;
-
if (!tim->avtl)
- error("Couldn't read AVTL chunk from file: '%s'", filename);
+ error("No AVTL chunk found in file: '%s'", filename);
+
+ if (stream->err())
+ error("Read error while parsing file '%s", filename);
+
+ delete stream;
int num = (avtlChunkSize < TIM::kCountFuncs) ? avtlChunkSize : (int)TIM::kCountFuncs;
for (int i = 0; i < num; ++i)