Skip to content

Commit b91456b

Browse files
TreeHunter9Artyom Ivanov
authored andcommitted
fix(pag): Incorrect calculation of last used page (#8772)
* fix(pag): Incorrect calculation of last used page * Revert "fix(pag): Incorrect calculation of last used page" This reverts commit 91a29a8. * fix(pag): Incorrect calculation of last used page --------- Co-authored-by: Artyom Ivanov <artyom.ivanov@red-soft.ru>
1 parent 338e825 commit b91456b

1 file changed

Lines changed: 16 additions & 13 deletions

File tree

src/jrd/pag.cpp

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2295,27 +2295,30 @@ ULONG PageSpace::lastUsedPage()
22952295

22962296
page_inv_page* pip = (page_inv_page*) window.win_buffer;
22972297

2298-
int last_bit = pip->pip_used;
2299-
int byte_num = last_bit / 8;
2300-
UCHAR mask = 1 << (last_bit % 8);
2301-
while (last_bit >= 0 && (pip->pip_bits[byte_num] & mask))
2298+
int last_bit = pip->pip_used - 1;
2299+
if (pip->pip_used > 0)
23022300
{
2303-
if (mask == 1)
2301+
int byte_num = last_bit / 8;
2302+
UCHAR mask = 1 << (last_bit % 8);
2303+
while (last_bit >= 0 && (pip->pip_bits[byte_num] & mask))
23042304
{
2305-
mask = 0x80;
2306-
byte_num--;
2307-
//fb_assert(byte_num > -1); ???
2308-
}
2309-
else
2310-
mask >>= 1;
2305+
if (mask == 1)
2306+
{
2307+
mask = 0x80;
2308+
byte_num--;
2309+
//fb_assert(byte_num > -1); ???
2310+
}
2311+
else
2312+
mask >>= 1;
23112313

2312-
last_bit--;
2314+
last_bit--;
2315+
}
23132316
}
23142317

23152318
CCH_RELEASE(tdbb, &window);
23162319
pipMaxKnown = pipLast;
23172320

2318-
return last_bit + (pipLast == pipFirst ? 0 : pipLast);
2321+
return last_bit + 1 + (pipLast == pipFirst ? 0 : pipLast);
23192322
}
23202323

23212324
ULONG PageSpace::lastUsedPage(const Database* dbb)

0 commit comments

Comments
 (0)