From 7279a722892772209a54c955013664f59fc9ba62 Mon Sep 17 00:00:00 2001
From: marko <>
Date: Fri, 30 Jun 2006 09:49:32 +0000
Subject: [PATCH] branches/zip: Improve assertions related to the linked lists
 of records on B-tree index pages.

page_rec_set_next(): Assert that rec != next.

rec_get_next_ptr(), rec_get_next_offs(): On compact pages, assert that
there are at least REC_N_NEW_EXTRA_BYTES + 1 between records.

page_cur_insert_rec_write_log(): Replace a buf_frame_align() call
with ut_align_offset().

page_cur_insert_rec_low(): Assert that current_rec != insert_rec.
---
 include/page0page.ic |  1 +
 include/rem0rec.ic   | 12 ++++++++++++
 page/page0cur.c      |  5 +++--
 3 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/include/page0page.ic b/include/page0page.ic
index 433dabcf4a8..e819a8dc0b0 100644
--- a/include/page0page.ic
+++ b/include/page0page.ic
@@ -652,6 +652,7 @@ page_rec_set_next(
 
 	ut_ad(page_rec_check(rec));
 	ut_ad(!page_rec_is_supremum(rec));
+	ut_ad(rec != next);
 
 	ut_ad(!next || !page_rec_is_infimum(next));
 	ut_ad(!next || ut_align_down(rec, UNIV_PAGE_SIZE)
diff --git a/include/rem0rec.ic b/include/rem0rec.ic
index f593f05d1de..56d5b2662c7 100644
--- a/include/rem0rec.ic
+++ b/include/rem0rec.ic
@@ -269,6 +269,12 @@ rec_get_next_ptr(
 			+ ut_align_offset(rec, UNIV_PAGE_SIZE)
 			< UNIV_PAGE_SIZE);
 #endif
+		/* There must be at least REC_N_NEW_EXTRA_BYTES + 1
+		between each record. */
+		ut_ad((field_value > REC_N_NEW_EXTRA_BYTES
+				&& field_value < 32768)
+			|| field_value < (uint16) -REC_N_NEW_EXTRA_BYTES);
+
 		return((byte*) ut_align_down(rec, UNIV_PAGE_SIZE)
 			+ ut_align_offset(rec + field_value, UNIV_PAGE_SIZE));
 	} else {
@@ -323,6 +329,12 @@ rec_get_next_offs(
 			return(0);
 		}
 
+		/* There must be at least REC_N_NEW_EXTRA_BYTES + 1
+		between each record. */
+		ut_ad((field_value > REC_N_NEW_EXTRA_BYTES
+				&& field_value < 32768)
+			|| field_value < (uint16) -REC_N_NEW_EXTRA_BYTES);
+
 		return(ut_align_offset(rec + field_value, UNIV_PAGE_SIZE));
 	} else {
 		ut_ad(field_value < UNIV_PAGE_SIZE);
diff --git a/page/page0cur.c b/page/page0cur.c
index a87652183e9..36757381ce7 100644
--- a/page/page0cur.c
+++ b/page/page0cur.c
@@ -621,8 +621,8 @@ page_cur_insert_rec_write_log(
 
 		log_end = &log_ptr[2 + 5 + 1 + 5 + 5 + MLOG_BUF_MARGIN];
 		/* Write the cursor rec offset as a 2-byte ulint */
-		mach_write_to_2(log_ptr, cursor_rec
-					- buf_frame_align(cursor_rec));
+		mach_write_to_2(log_ptr,
+				ut_align_offset(cursor_rec, UNIV_PAGE_SIZE));
 		log_ptr += 2;
 	} else {
 		log_ptr = mlog_open(mtr, 5 + 1 + 5 + 5 + MLOG_BUF_MARGIN);
@@ -1022,6 +1022,7 @@ use_heap:
 
 	/* 4. Insert the record in the linked list of records */
 	current_rec = cursor->rec;
+	ut_ad(current_rec != insert_rec);
 
 	{
 		/* next record after current before the insertion */