Skip to content

Commit 9c5d132

Browse files
committed
io: ReadVersion should always take both position and byte count
1 parent 3ce353d commit 9c5d132

1 file changed

Lines changed: 11 additions & 12 deletions

File tree

io/io/src/TBufferFile.cxx

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3007,14 +3007,15 @@ void TBufferFile::SkipVersion(const TClass *cl)
30073007

30083008
Version_t TBufferFile::ReadVersion(UInt_t *startpos, UInt_t *bcnt, const TClass *cl)
30093009
{
3010+
assert((!startpos && !bcnt) || (startpos && bcnt)); // both or none should be set
3011+
30103012
Version_t version;
30113013

30123014
if (startpos) {
30133015
// before reading object save start position
30143016
auto full_startpos = fBufCur - fBuffer;
30153017
*startpos = full_startpos <= kMaxCountPosition ? UInt_t(full_startpos) : kOverflowPosition;
3016-
if (bcnt)
3017-
fByteCountStack.push_back(full_startpos);
3018+
fByteCountStack.push_back(full_startpos);
30183019
}
30193020

30203021
// read byte count (older files don't have byte count)
@@ -3039,20 +3040,19 @@ Version_t TBufferFile::ReadVersion(UInt_t *startpos, UInt_t *bcnt, const TClass
30393040
v.cnt = 0;
30403041
}
30413042
if (bcnt) {
3043+
// We also have (asserted) that (startpos != nullptr)
30423044
if (!v.cnt) {
30433045
// no byte count stored
30443046
*bcnt = 0;
3045-
if (startpos) // Undo the push_back only if it happened.
3046-
fByteCountStack.pop_back();
3047+
fByteCountStack.pop_back();
30473048
} else {
30483049
*bcnt = (v.cnt & ~kByteCountMask);
30493050
if (*bcnt == 0) {
30503051
// The byte count was stored but is zero, this means the data
30513052
// did not fit and thus we stored it in 'fByteCounts' instead.
30523053
// Mark this case by setting startpos to kOverflowCount.
30533054
*bcnt = kOverflowCount;
3054-
if (startpos)
3055-
*startpos = kOverflowPosition;
3055+
*startpos = kOverflowPosition;
30563056
}
30573057
}
30583058
}
@@ -3146,14 +3146,15 @@ Version_t TBufferFile::ReadVersion(UInt_t *startpos, UInt_t *bcnt, const TClass
31463146

31473147
Version_t TBufferFile::ReadVersionNoCheckSum(UInt_t *startpos, UInt_t *bcnt)
31483148
{
3149+
assert((!startpos && !bcnt) || (startpos && bcnt)); // both or none should be set
3150+
31493151
Version_t version;
31503152

31513153
if (startpos) {
31523154
// before reading object save start position
31533155
auto full_startpos = fBufCur - fBuffer;
31543156
*startpos = full_startpos < kMaxCountPosition ? UInt_t(full_startpos) : kOverflowPosition;
3155-
if (bcnt)
3156-
fByteCountStack.push_back(full_startpos);
3157+
fByteCountStack.push_back(full_startpos);
31573158
}
31583159

31593160
// read byte count (older files don't have byte count)
@@ -3181,17 +3182,15 @@ Version_t TBufferFile::ReadVersionNoCheckSum(UInt_t *startpos, UInt_t *bcnt)
31813182
if (!v.cnt) {
31823183
// no byte count stored
31833184
*bcnt = 0;
3184-
if (startpos) // Undo the push_back only if it happened.
3185-
fByteCountStack.pop_back();
3185+
fByteCountStack.pop_back();
31863186
} else {
31873187
*bcnt = (v.cnt & ~kByteCountMask);
31883188
if (*bcnt == 0) {
31893189
// The byte count was stored but is zero, this means the data
31903190
// did not fit and thus we stored it in 'fByteCounts' instead.
31913191
// Mark this case by setting startpos to kOverflowCount.
31923192
*bcnt = kOverflowCount;
3193-
if (startpos)
3194-
*startpos = kOverflowPosition;
3193+
*startpos = kOverflowPosition;
31953194
}
31963195
}
31973196
}

0 commit comments

Comments
 (0)