mirror of
https://github.com/fadden/nulib2.git
synced 2025-01-14 01:29:43 +00:00
Fixed a bug in Nu_RecordSet_MoveAllRecords() that left origRecordSet in
an unhappy state after deleting a record. Added a bunch of asserts to catch similar problems in the future.
This commit is contained in:
parent
e546f96f9a
commit
104f34629c
@ -2511,6 +2511,12 @@ bail:
|
||||
*pStatusFlags |= kNuFlushReadOnly;
|
||||
}
|
||||
}
|
||||
|
||||
/* last-minute sanity check */
|
||||
Assert(pArchive->origRecordSet.numRecords == 0 ||
|
||||
(pArchive->origRecordSet.nuRecordHead != nil &&
|
||||
pArchive->origRecordSet.nuRecordTail != nil));
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
|
@ -349,6 +349,7 @@ Nu_RecordSet_FreeAllRecords(NuArchive* pArchive, NuRecordSet* pRecordSet)
|
||||
|
||||
if (!pRecordSet->loaded) {
|
||||
Assert(pRecordSet->nuRecordHead == nil);
|
||||
Assert(pRecordSet->nuRecordTail == nil);
|
||||
Assert(pRecordSet->numRecords == 0);
|
||||
return kNuErrNone;
|
||||
}
|
||||
@ -545,19 +546,29 @@ Nu_RecordSet_MoveAllRecords(NuArchive* pArchive, NuRecordSet* pDstSet,
|
||||
return kNuErrNone;
|
||||
#endif
|
||||
|
||||
if (pDstSet->nuRecordHead == nil) {
|
||||
/* empty dst list */
|
||||
pDstSet->nuRecordHead = pSrcSet->nuRecordHead;
|
||||
pDstSet->nuRecordTail = pSrcSet->nuRecordTail;
|
||||
pDstSet->numRecords = pSrcSet->numRecords;
|
||||
pDstSet->loaded = true;
|
||||
/* move records over */
|
||||
if (Nu_RecordSet_GetNumRecords(pSrcSet)) {
|
||||
Assert(pSrcSet->nuRecordHead != nil);
|
||||
Assert(pSrcSet->nuRecordTail != nil);
|
||||
if (pDstSet->nuRecordHead == nil) {
|
||||
/* empty dst list */
|
||||
Assert(pDstSet->nuRecordTail == nil);
|
||||
pDstSet->nuRecordHead = pSrcSet->nuRecordHead;
|
||||
pDstSet->nuRecordTail = pSrcSet->nuRecordTail;
|
||||
pDstSet->numRecords = pSrcSet->numRecords;
|
||||
pDstSet->loaded = true;
|
||||
} else {
|
||||
/* append to dst list */
|
||||
Assert(pDstSet->loaded);
|
||||
Assert(pDstSet->nuRecordTail != nil);
|
||||
pDstSet->nuRecordTail->pNext = pSrcSet->nuRecordHead;
|
||||
pDstSet->nuRecordTail = pSrcSet->nuRecordTail;
|
||||
pDstSet->numRecords += pSrcSet->numRecords;
|
||||
}
|
||||
} else {
|
||||
/* append to dst list */
|
||||
Assert(pDstSet->loaded);
|
||||
Assert(pDstSet->nuRecordTail != nil);
|
||||
pDstSet->nuRecordTail->pNext = pSrcSet->nuRecordHead;
|
||||
pDstSet->nuRecordTail = pSrcSet->nuRecordTail;
|
||||
pDstSet->numRecords += pSrcSet->numRecords;
|
||||
/* no records in src set */
|
||||
Assert(pSrcSet->nuRecordHead == nil);
|
||||
Assert(pSrcSet->nuRecordTail == nil);
|
||||
}
|
||||
|
||||
/* nuke all pointers in original list */
|
||||
|
Loading…
x
Reference in New Issue
Block a user