Skip to content

Commit

Permalink
Fix off by one in PointerBase
Browse files Browse the repository at this point in the history
Summary:
Since the zero index is reserved for nullptr, we can actually
accommodate only 1023 segments (with 4MB segments), as opposed
to 1024.

Reviewed By: dulinriley

Differential Revision: D28309676

fbshipit-source-id: 654b8a257984cdd44286259d8073edba0d12e78a
  • Loading branch information
neildhar authored and facebook-github-bot committed May 10, 2021
1 parent b761482 commit f3b1f0c
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions include/hermes/VM/PointerBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,10 @@ class PointerBase {
/// segmentMap_[0], which is used for the null pointer
/// representation.
using SegmentPtr = void *;
static constexpr unsigned kMaxSegments = 1 << (32 - AlignedStorage::kLogSize);
/// We add one entry so that segmentMap_[0] can contain the null pointer.
static constexpr unsigned kSegmentMapSize = kMaxSegments + 1;
static constexpr unsigned kSegmentMapSize = 1
<< (32 - AlignedStorage::kLogSize);
/// We subtract one entry so that segmentMap_[0] can contain the null pointer.
static constexpr unsigned kMaxSegments = kSegmentMapSize - 1;
SegmentPtr segmentMap_[kSegmentMapSize];
#endif // HERMESVM_COMPRESSED_POINTERS
};
Expand Down

0 comments on commit f3b1f0c

Please sign in to comment.