From ada1d8de0446c65c2d35e07c5de87589954723c5 Mon Sep 17 00:00:00 2001 From: Andy McFadden Date: Tue, 11 Mar 2003 22:11:22 +0000 Subject: [PATCH] Fixed a bug that would cause things to go south if you added files in a certain pattern. The problem was an uninitialized "fakeThreads". Added some comments and tweaked an error message while I was at it. --- nufxlib-0/FileIO.c | 4 ++-- nufxlib-0/NufxLib.h | 2 ++ nufxlib-0/Record.c | 8 ++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/nufxlib-0/FileIO.c b/nufxlib-0/FileIO.c index 3fe04d7..0b63700 100644 --- a/nufxlib-0/FileIO.c +++ b/nufxlib-0/FileIO.c @@ -1232,8 +1232,8 @@ Nu_CopyFileSection(NuArchive* pArchive, FILE* dstFp, FILE* srcFp, long length) if (err != kNuErrNone) { Nu_ReportError(NU_BLOB, err, "Nu_FRead failed while copying file section " - "(fp=0x%08lx, readLen=%ld, err=%d)\n", - (long) srcFp, readLen, err); + "(fp=0x%08lx, readLen=%ld, length=%ld, err=%d)\n", + (long) srcFp, readLen, length, err); goto bail; } err = Nu_FWrite(dstFp, pArchive->compBuf, readLen); diff --git a/nufxlib-0/NufxLib.h b/nufxlib-0/NufxLib.h index 331fcae..a1c5539 100644 --- a/nufxlib-0/NufxLib.h +++ b/nufxlib-0/NufxLib.h @@ -412,6 +412,8 @@ typedef struct NuThread { /* * NuFX "record" definition. + * + * (Note to developers: update Nu_AddRecord if this changes.) */ #define kNufxIDLen 4 /* len of 'NuFX' with funky MSBs */ #define kNuReasonableAttribCount 256 diff --git a/nufxlib-0/Record.c b/nufxlib-0/Record.c index a143b8d..1b2924d 100644 --- a/nufxlib-0/Record.c +++ b/nufxlib-0/Record.c @@ -1265,6 +1265,11 @@ Nu_WriteRecordHeader(NuArchive* pArchive, NuRecord* pRecord, FILE* fp) /* * Update values for misc record fields. + * + * Note that, despite having written the record header, we can still + * have "fake" threads. This is because WriteThreadHeaders only saves + * the real ones. This is in line with our policy of not altering + * anything we don't have to. */ pRecord->recHeaderLength = bytesWritten + pRecord->recTotalThreads * kNuThreadHeaderSize; @@ -2295,9 +2300,12 @@ Nu_AddRecord(NuArchive* pArchive, const NuFileDetails* pFileDetails, pNewRecord->recFilenameLength = 0; pNewRecord->recordIdx = Nu_GetNextRecordIdx(pArchive); + pNewRecord->threadFilename = nil; pNewRecord->newFilename = strdup(pFileDetails->storageName); pNewRecord->filename = pNewRecord->newFilename; + pNewRecord->recHeaderLength = -1; pNewRecord->totalCompLength = 0; + pNewRecord->fakeThreads = 0; pNewRecord->fileOffset = -1; /*