mirror of
https://github.com/fadden/nulib2.git
synced 2024-05-28 23:41:29 +00:00
Fixed minor bugs when trying to open a file that doesn't actually contain
an archive. Spotted by valgrind.
This commit is contained in:
parent
9d524310f2
commit
6dbf0dced9
|
@ -40,6 +40,9 @@ static const uchar kNuSHKSEAID[] =
|
|||
#define kNuSEALength2 12001 /* length of archive (4B?) */
|
||||
|
||||
|
||||
static void Nu_CloseAndFree(NuArchive* pArchive);
|
||||
|
||||
|
||||
/*
|
||||
* ===========================================================================
|
||||
* Archive and MasterHeader utility functions
|
||||
|
@ -703,6 +706,7 @@ Nu_OpenRO(const char* archivePathname, NuArchive** ppArchive)
|
|||
|
||||
pArchive->openMode = kNuOpenRO;
|
||||
pArchive->archiveFp = fp;
|
||||
fp = nil;
|
||||
pArchive->archivePathname = strdup(archivePathname);
|
||||
|
||||
err = Nu_ReadMasterHeader(pArchive);
|
||||
|
@ -710,8 +714,10 @@ Nu_OpenRO(const char* archivePathname, NuArchive** ppArchive)
|
|||
|
||||
bail:
|
||||
if (err != kNuErrNone) {
|
||||
if (pArchive != nil)
|
||||
(void) Nu_NuArchiveFree(pArchive);
|
||||
if (pArchive != nil) {
|
||||
(void) Nu_CloseAndFree(pArchive);
|
||||
*ppArchive = nil;
|
||||
}
|
||||
if (fp != nil)
|
||||
fclose(fp);
|
||||
}
|
||||
|
@ -908,8 +914,8 @@ Nu_OpenRW(const char* archivePathname, const char* tmpPathname, ulong flags,
|
|||
|
||||
pArchive->openMode = kNuOpenRW;
|
||||
pArchive->newlyCreated = newlyCreated;
|
||||
pArchive->archiveFp = fp;
|
||||
pArchive->archivePathname = strdup(archivePathname);
|
||||
pArchive->archiveFp = fp;
|
||||
fp = nil;
|
||||
pArchive->tmpFp = tmpFp;
|
||||
tmpFp = nil;
|
||||
|
@ -926,7 +932,7 @@ Nu_OpenRW(const char* archivePathname, const char* tmpPathname, ulong flags,
|
|||
bail:
|
||||
if (err != kNuErrNone) {
|
||||
if (pArchive != nil) {
|
||||
(void) Nu_NuArchiveFree(pArchive);
|
||||
(void) Nu_CloseAndFree(pArchive);
|
||||
*ppArchive = nil;
|
||||
}
|
||||
if (fp != nil)
|
||||
|
@ -1063,6 +1069,9 @@ Nu_Close(NuArchive* pArchive)
|
|||
DBUG(("--- Close NuFlush status was 0x%4lx\n", flushStatus));
|
||||
}
|
||||
|
||||
if (err != kNuErrNone) {
|
||||
DBUG(("--- Nu_Close returning error %d\n", err));
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,11 @@
|
|||
#include "NufxLibPriv.h"
|
||||
|
||||
|
||||
/* this makes valgrind and purify happy, at some tiny cost in speed */
|
||||
#define CLEAN_INIT =0
|
||||
/*#define CLEAN_INIT */
|
||||
|
||||
|
||||
/*
|
||||
* ===========================================================================
|
||||
* Read and write
|
||||
|
@ -39,7 +44,7 @@ Nu_ReadOneC(NuArchive* pArchive, FILE* fp, ushort* pCrc)
|
|||
uchar
|
||||
Nu_ReadOne(NuArchive* pArchive, FILE* fp)
|
||||
{
|
||||
ushort dummyCrc /*= 0*/;
|
||||
ushort dummyCrc CLEAN_INIT;
|
||||
return Nu_ReadOneC(pArchive, fp, &dummyCrc);
|
||||
}
|
||||
|
||||
|
@ -59,7 +64,7 @@ Nu_WriteOneC(NuArchive* pArchive, FILE* fp, uchar val, ushort* pCrc)
|
|||
void
|
||||
Nu_WriteOne(NuArchive* pArchive, FILE* fp, uchar val)
|
||||
{
|
||||
ushort dummyCrc /*= 0*/;
|
||||
ushort dummyCrc CLEAN_INIT;
|
||||
Nu_WriteOneC(pArchive, fp, val, &dummyCrc);
|
||||
}
|
||||
|
||||
|
@ -87,7 +92,7 @@ Nu_ReadTwoC(NuArchive* pArchive, FILE* fp, ushort* pCrc)
|
|||
ushort
|
||||
Nu_ReadTwo(NuArchive* pArchive, FILE* fp)
|
||||
{
|
||||
ushort dummyCrc /*= 0*/;
|
||||
ushort dummyCrc CLEAN_INIT;
|
||||
return Nu_ReadTwoC(pArchive, fp, &dummyCrc);
|
||||
}
|
||||
|
||||
|
@ -116,7 +121,7 @@ Nu_WriteTwoC(NuArchive* pArchive, FILE* fp, ushort val, ushort* pCrc)
|
|||
void
|
||||
Nu_WriteTwo(NuArchive* pArchive, FILE* fp, ushort val)
|
||||
{
|
||||
ushort dummyCrc /*= 0*/;
|
||||
ushort dummyCrc CLEAN_INIT;
|
||||
Nu_WriteTwoC(pArchive, fp, val, &dummyCrc);
|
||||
}
|
||||
|
||||
|
@ -148,7 +153,7 @@ Nu_ReadFourC(NuArchive* pArchive, FILE* fp, ushort* pCrc)
|
|||
ulong
|
||||
Nu_ReadFour(NuArchive* pArchive, FILE* fp)
|
||||
{
|
||||
ushort dummyCrc /*= 0*/;
|
||||
ushort dummyCrc CLEAN_INIT;
|
||||
return Nu_ReadFourC(pArchive, fp, &dummyCrc);
|
||||
}
|
||||
|
||||
|
@ -183,7 +188,7 @@ Nu_WriteFourC(NuArchive* pArchive, FILE* fp, ulong val, ushort* pCrc)
|
|||
void
|
||||
Nu_WriteFour(NuArchive* pArchive, FILE* fp, ulong val)
|
||||
{
|
||||
ushort dummyCrc /*=0*/;
|
||||
ushort dummyCrc CLEAN_INIT;
|
||||
Nu_WriteFourC(pArchive, fp, val, &dummyCrc);
|
||||
}
|
||||
|
||||
|
@ -236,7 +241,7 @@ Nu_ReadDateTimeC(NuArchive* pArchive, FILE* fp, ushort* pCrc)
|
|||
NuDateTime
|
||||
Nu_ReadDateTime(NuArchive* pArchive, FILE* fp, ushort* pCrc)
|
||||
{
|
||||
ushort dummyCrc /*= 0*/;
|
||||
ushort dummyCrc CLEAN_INIT;
|
||||
return Nu_ReadDateTimeC(pArchive, fp, &dummyCrc);
|
||||
}
|
||||
|
||||
|
@ -283,7 +288,7 @@ Nu_WriteDateTimeC(NuArchive* pArchive, FILE* fp, NuDateTime dateTime,
|
|||
void
|
||||
Nu_WriteDateTime(NuArchive* pArchive, FILE* fp, NuDateTime dateTime)
|
||||
{
|
||||
ushort dummyCrc /*= 0*/;
|
||||
ushort dummyCrc CLEAN_INIT;
|
||||
Nu_WriteDateTimeC(pArchive, fp, dateTime, &dummyCrc);
|
||||
}
|
||||
|
||||
|
@ -314,7 +319,7 @@ Nu_ReadBytesC(NuArchive* pArchive, FILE* fp, void* vbuffer, long count,
|
|||
void
|
||||
Nu_ReadBytes(NuArchive* pArchive, FILE* fp, void* vbuffer, long count)
|
||||
{
|
||||
ushort dummyCrc /*= 0*/;
|
||||
ushort dummyCrc CLEAN_INIT;
|
||||
Nu_ReadBytesC(pArchive, fp, vbuffer, count, &dummyCrc);
|
||||
}
|
||||
|
||||
|
@ -345,7 +350,7 @@ Nu_WriteBytesC(NuArchive* pArchive, FILE* fp, const void* vbuffer, long count,
|
|||
void
|
||||
Nu_WriteBytes(NuArchive* pArchive, FILE* fp, const void* vbuffer, long count)
|
||||
{
|
||||
ushort dummyCrc /*= 0*/;
|
||||
ushort dummyCrc CLEAN_INIT;
|
||||
Nu_WriteBytesC(pArchive, fp, vbuffer, count, &dummyCrc);
|
||||
}
|
||||
|
||||
|
@ -381,9 +386,9 @@ Nu_SeekArchive(NuArchive* pArchive, FILE* fp, long offset, int ptrname)
|
|||
{
|
||||
if (Nu_IsStreaming(pArchive)) {
|
||||
Assert(ptrname == SEEK_CUR);
|
||||
Assert(offset > 0);
|
||||
Assert(offset >= 0);
|
||||
|
||||
/* might be faster to fread a chunk at a time */
|
||||
/* OPT: might be faster to fread a chunk at a time */
|
||||
while (offset--)
|
||||
(void) getc(fp);
|
||||
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
#ifndef __MiscStuff__
|
||||
#define __MiscStuff__
|
||||
|
||||
#define VALGRIND /* assume we're using it */
|
||||
|
||||
#include "SysDefs.h"
|
||||
|
||||
/*
|
||||
|
@ -93,7 +95,7 @@ typedef uchar Boolean;
|
|||
|
||||
#else
|
||||
/* when debugging, fill Malloc blocks with junk, unless we're using Purify */
|
||||
#if !defined(PURIFY)
|
||||
#if !defined(PURIFY) && !defined(VALGRIND)
|
||||
#define DebugFill(addr, len) memset(addr, 0xa3, len)
|
||||
#else
|
||||
#define DebugFill(addr, len) ((void)0)
|
||||
|
@ -102,7 +104,6 @@ typedef uchar Boolean;
|
|||
#define DebugAbort() abort()
|
||||
#endif
|
||||
|
||||
#define kInvalidFill (0xa3)
|
||||
#define kInvalidPtr ((void*)0xa3a3a3a3)
|
||||
|
||||
#endif /*__MiscStuff__*/
|
||||
|
|
|
@ -764,7 +764,7 @@ NuError
|
|||
OpenArchiveReadOnly(NulibState* pState)
|
||||
{
|
||||
NuError err;
|
||||
NuArchive* pArchive;
|
||||
NuArchive* pArchive = nil;
|
||||
|
||||
assert(pState != nil);
|
||||
|
||||
|
@ -844,6 +844,11 @@ OpenArchiveReadOnly(NulibState* pState)
|
|||
BailError(err);
|
||||
|
||||
bail:
|
||||
if (err != kNuErrNone && pArchive != nil) {
|
||||
/* clean up */
|
||||
(void) NuClose(pArchive);
|
||||
NState_SetNuArchive(pState, nil);
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
|
@ -858,7 +863,7 @@ NuError
|
|||
OpenArchiveReadWrite(NulibState* pState)
|
||||
{
|
||||
NuError err = kNuErrNone;
|
||||
NuArchive* pArchive;
|
||||
NuArchive* pArchive = nil;
|
||||
char* tempName = nil;
|
||||
|
||||
assert(pState != nil);
|
||||
|
@ -930,6 +935,12 @@ OpenArchiveReadWrite(NulibState* pState)
|
|||
|
||||
bail:
|
||||
Free(tempName);
|
||||
if (err != kNuErrNone && pArchive != nil) {
|
||||
/* clean up */
|
||||
NuAbort(pArchive);
|
||||
(void) NuClose(pArchive);
|
||||
NState_SetNuArchive(pState, nil);
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
#ifndef __MiscStuff__
|
||||
#define __MiscStuff__
|
||||
|
||||
#define VALGRIND /* assume we're using it */
|
||||
|
||||
#include "SysDefs.h"
|
||||
|
||||
/*
|
||||
|
@ -93,7 +95,7 @@ typedef uchar Boolean;
|
|||
|
||||
#else
|
||||
/* when debugging, fill Malloc blocks with junk, unless we're using Purify */
|
||||
#if !defined(PURIFY)
|
||||
#if !defined(PURIFY) && !defined(VALGRIND)
|
||||
#define DebugFill(addr, len) memset(addr, 0xa3, len)
|
||||
#else
|
||||
#define DebugFill(addr, len) ((void)0)
|
||||
|
@ -102,7 +104,6 @@ typedef uchar Boolean;
|
|||
#define DebugAbort() abort()
|
||||
#endif
|
||||
|
||||
#define kInvalidFill (0xa3)
|
||||
#define kInvalidPtr ((void*)0xa3a3a3a3)
|
||||
|
||||
#endif /*__MiscStuff__*/
|
||||
|
|
Loading…
Reference in New Issue
Block a user