Skip to content

Commit d4bf367

Browse files
committed
Introduce named constants for BitNestedArchiveReader sentinel values
Replaced direct usage of `std::numeric_limits::max()` with descriptive `constexpr` variables (`kItemsCountUnset`, `kNoItemRead`) for `mCachedItemsCount` and `mLastReadItem`. This improves code readability and explicitly communicates the intent of these sentinel values.
1 parent bd03de4 commit d4bf367

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

src/bitnestedarchivereader.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ namespace bit7z {
3737
// Minimum value for the maximum memory usage allowed for the BufferQueue.
3838
constexpr std::uint64_t kMinMaxMemoryUsage = 4ULL * 1024 * 1024; // 4 MiB //-V112
3939

40+
// Sentinels: IInArchive::GetNumberOfItems/GetProperty/Extract all index items via UInt32,
41+
// so no archive can ever report more items than max() in the first place; safe to reserve as "unset".
42+
constexpr std::uint32_t kItemsCountUnset = std::numeric_limits< std::uint32_t >::max();
43+
constexpr std::uint32_t kNoItemRead = std::numeric_limits< std::uint32_t >::max();
44+
4045
namespace {
4146
auto getFreeRam() -> std::uint64_t {
4247
#if defined( _WIN64 ) || defined( _WIN32 )
@@ -128,8 +133,8 @@ BitNestedArchiveReader::BitNestedArchiveReader(
128133
mParentArchive{ parentArchive },
129134
mIndexInParent{ index },
130135
mMaxMemoryUsage{ std::max( getFreeRam() / 4, kMinMaxMemoryUsage ) },
131-
mCachedItemsCount{ std::numeric_limits< decltype( mCachedItemsCount ) >::max() },
132-
mLastReadItem{ std::numeric_limits< decltype( mLastReadItem ) >::max() },
136+
mCachedItemsCount{ kItemsCountUnset },
137+
mLastReadItem{ kNoItemRead },
133138
mOpenCount{ 0 },
134139
mOperationInProgress{ false } {}
135140

@@ -161,7 +166,7 @@ auto BitNestedArchiveReader::itemProperty( std::uint32_t index, BitProperty prop
161166
}
162167

163168
auto BitNestedArchiveReader::itemsCount() const -> std::uint32_t {
164-
if ( mCachedItemsCount != std::numeric_limits< decltype( mCachedItemsCount ) >::max() ) {
169+
if ( mCachedItemsCount != kItemsCountUnset ) {
165170
return mCachedItemsCount;
166171
}
167172

@@ -271,7 +276,7 @@ void BitNestedArchiveReader::reopenIfNeeded( std::uint32_t index ) const {
271276

272277
// Poisoning mLastReadItem before anything after this function call can throw, so a failure forces
273278
// the next operation to reopen instead of reusing a possibly-advanced stream.
274-
mLastReadItem = std::numeric_limits< decltype( mLastReadItem ) >::max();
279+
mLastReadItem = kNoItemRead;
275280
}
276281

277282
auto BitNestedArchiveReader::needReopen( std::uint32_t index ) const noexcept -> bool {

0 commit comments

Comments
 (0)