From 84acc0e803d34051c5e7b737c2544d3970cb8155 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Wed, 4 Apr 2012 05:22:26 -0700 Subject: [PATCH] ITS#7219 fixup keysize in previous commit --- libraries/libmdb/mdb.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/libraries/libmdb/mdb.c b/libraries/libmdb/mdb.c index 6952d88..ffbfefc 100644 --- a/libraries/libmdb/mdb.c +++ b/libraries/libmdb/mdb.c @@ -5057,7 +5057,7 @@ mdb_update_key(MDB_page *mp, indx_t indx, MDB_val *key) MDB_node *node; char *base; size_t len; - int delta; + int delta, delta0; indx_t ptr, i, numkeys; DKBUF; @@ -5077,7 +5077,11 @@ mdb_update_key(MDB_page *mp, indx_t indx, MDB_val *key) } #endif - delta = key->mv_size - node->mn_ksize; + delta0 = delta = key->mv_size - node->mn_ksize; + + /* Must be 2-byte aligned. If new key is + * shorter by 1, the shift will be skipped. + */ delta += (delta & 1); if (delta) { if (delta > 0 && SIZELEFT(mp) < delta) { @@ -5097,9 +5101,12 @@ mdb_update_key(MDB_page *mp, indx_t indx, MDB_val *key) mp->mp_upper -= delta; node = NODEPTR(mp, indx); - node->mn_ksize = key->mv_size; } + /* But even if no shift was needed, update ksize */ + if (delta0) + node->mn_ksize = key->mv_size; + if (key->mv_size) memcpy(NODEKEY(node), key->mv_data, key->mv_size);