Skip to content

Commit f09fe70

Browse files
committed
Always dump the bytes when an unknown chunk is skipped. An unknown chunk is always a bug.
1 parent cd7710d commit f09fe70

File tree

4 files changed

+9
-44
lines changed

4 files changed

+9
-44
lines changed

Diff for: src/lcf/reader_lcf.h

+2-20
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,6 @@
2525
#include "lcf/reader_util.h"
2626
#include "lcf/encoder.h"
2727

28-
/*
29-
* Calls SkipDebug() instead of Skip() for debug builds.
30-
*/
31-
#ifdef _DEBUG
32-
#define Skip(x) SkipDebug(x, __FILE__)
33-
#endif
34-
3528
namespace lcf {
3629

3730
/**
@@ -189,27 +182,16 @@ class LcfReader {
189182
*/
190183
int Peek();
191184

192-
#ifdef _DEBUG
193-
/**
194-
* The skip-function for debug builds.
195-
* Same as Skip() but also dumps the content of the
196-
* skipped chunk to stderr.
197-
*
198-
* @param chunk_info chunk that will be skipped.
199-
* @param srclife name of the calling cpp-file.
200-
*/
201-
void SkipDebug(const struct LcfReader::Chunk& chunk_info, const char* srcfile);
202-
#else
203185
/**
204186
* Skips a chunk (seeks chunk_info.length bytes from
205187
* the current stream position).
206188
* In debug builds, dumps the content of the
207189
* skipped chunk to stderr.
208190
*
209191
* @param chunk_info chunk that will be skipped.
192+
* @param where name of the caller that caused the skip, for finding unknown chunks
210193
*/
211-
void Skip(const struct LcfReader::Chunk& chunk_info);
212-
#endif
194+
void Skip(const struct LcfReader::Chunk& chunk_info, const char* where);
213195

214196
/**
215197
* Encodes a string to UTF-8 using the set encoding

Diff for: src/ldb_equipment.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void RawStruct<rpg::Equipment>::ReadLcf(rpg::Equipment& ref, LcfReader& stream,
3333
chunk_info.ID = 0x33;
3434
chunk_info.length = length;
3535

36-
stream.Skip(chunk_info);
36+
stream.Skip(chunk_info, "Equipment");
3737

3838
return;
3939
}

Diff for: src/reader_lcf.cpp

+3-20
Original file line numberDiff line numberDiff line change
@@ -258,22 +258,10 @@ int LcfReader::Peek() {
258258
return stream.peek();
259259
}
260260

261-
#ifdef _DEBUG
262-
void LcfReader::SkipDebug(const struct LcfReader::Chunk& chunk_info, const char* srcfile) {
263-
// Dump the Chunk Data in Debug Mode
264-
#ifdef _WIN32
265-
const char* srcfilename = strrchr(srcfile, '\\');
266-
#else
267-
const char* srcfilename = strrchr(srcfile, '/');
268-
#endif
269-
if (srcfilename == NULL) {
270-
srcfilename = srcfile;
271-
} else {
272-
srcfilename++;
273-
}
261+
void LcfReader::Skip(const struct LcfReader::Chunk& chunk_info, const char* where) {
274262
fprintf(stderr, "Skipped Chunk %02X (%" PRIu32 " byte) in lcf at %" PRIX32 " (%s)\n",
275-
chunk_info.ID, chunk_info.length, Tell(),
276-
srcfilename);
263+
chunk_info.ID, chunk_info.length, Tell(), where);
264+
277265
for (uint32_t i = 0; i < chunk_info.length; ++i) {
278266
uint8_t byte;
279267
LcfReader::Read(byte);
@@ -287,11 +275,6 @@ void LcfReader::SkipDebug(const struct LcfReader::Chunk& chunk_info, const char*
287275
}
288276
fprintf(stderr, "\n");
289277
}
290-
#else
291-
void LcfReader::Skip(const struct LcfReader::Chunk& chunk_info) {
292-
Seek((size_t)chunk_info.length, FromCurrent);
293-
}
294-
#endif
295278

296279
void LcfReader::SetError(const char* fmt, ...) {
297280
va_list args;

Diff for: src/reader_struct_impl.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,13 @@ void Struct<S>::ReadLcf(S& obj, LcfReader& stream) {
7878
it->second->ReadLcf(obj, stream, chunk_info.length);
7979
const uint32_t bytes_read = stream.Tell() - off;
8080
if (bytes_read != chunk_info.length) {
81-
fprintf(stderr, "Warning: Corrupted Chunk 0x%02" PRIx32 " (size: %" PRIu32 ", pos: 0x%" PRIx32 "): %s : Read %" PRIu32 " bytes! Reseting...\n",
82-
chunk_info.ID, chunk_info.length, off, it->second->name, bytes_read);
81+
fprintf(stderr, "%s: Corrupted Chunk 0x%02" PRIx32 " (size: %" PRIu32 ", pos: 0x%" PRIx32 "): %s : Read %" PRIu32 " bytes! Reseting...\n",
82+
Struct<S>::name, chunk_info.ID, chunk_info.length, off, it->second->name, bytes_read);
8383
stream.Seek(off + chunk_info.length);
8484
}
8585
}
8686
else {
87-
stream.Skip(chunk_info);
87+
stream.Skip(chunk_info, Struct<S>::name);
8888
}
8989
}
9090
}

0 commit comments

Comments
 (0)