mirror of
https://github.com/MariaDB/server.git
synced 2026-05-17 20:37:12 +02:00
mroonga: correct offsetof calculation
Using a null pointer as a basic for calculation was undefined behaviour.
This commit is contained in:
parent
db4763a0d1
commit
2ba49bd804
2 changed files with 9 additions and 9 deletions
4
storage/mroonga/vendor/groonga/lib/db.c
vendored
4
storage/mroonga/vendor/groonga/lib/db.c
vendored
|
|
@ -969,8 +969,8 @@ calc_rec_size(grn_table_flags flags, uint32_t max_n_subrecs, uint32_t range_size
|
|||
*subrec_size = range_size + sizeof(uint32_t) + sizeof(uint32_t);
|
||||
break;
|
||||
}
|
||||
*value_size = (uintptr_t)GRN_RSET_SUBRECS_NTH((((grn_rset_recinfo *)0)->subrecs),
|
||||
*subrec_size, max_n_subrecs);
|
||||
*value_size = (uintptr_t) GRN_RSET_SUBRECS_NTH(offsetof(grn_rset_recinfo, subrecs),
|
||||
*subrec_size, max_n_subrecs);
|
||||
} else {
|
||||
*value_size = range_size;
|
||||
}
|
||||
|
|
|
|||
14
storage/mroonga/vendor/groonga/lib/hash.c
vendored
14
storage/mroonga/vendor/groonga/lib/hash.c
vendored
|
|
@ -1727,15 +1727,15 @@ grn_io_hash_calculate_entry_size(uint32_t key_size, uint32_t value_size,
|
|||
{
|
||||
if (flags & GRN_OBJ_KEY_VAR_SIZE) {
|
||||
if (flags & GRN_OBJ_KEY_LARGE) {
|
||||
return (uintptr_t)((grn_io_hash_entry_large *)0)->value + value_size;
|
||||
return offsetof(grn_io_hash_entry_large, value) + value_size;
|
||||
} else {
|
||||
return (uintptr_t)((grn_io_hash_entry_normal *)0)->value + value_size;
|
||||
return offsetof(grn_io_hash_entry_normal, value) + value_size;
|
||||
}
|
||||
} else {
|
||||
if (key_size == sizeof(uint32_t)) {
|
||||
return (uintptr_t)((grn_plain_hash_entry *)0)->value + value_size;
|
||||
return offsetof(grn_plain_hash_entry, value) + value_size;
|
||||
} else {
|
||||
return (uintptr_t)((grn_rich_hash_entry *)0)->key_and_value
|
||||
return offsetof(grn_rich_hash_entry, key_and_value)
|
||||
+ key_size + value_size;
|
||||
}
|
||||
}
|
||||
|
|
@ -1865,12 +1865,12 @@ grn_tiny_hash_calculate_entry_size(uint32_t key_size, uint32_t value_size,
|
|||
{
|
||||
uint32_t entry_size;
|
||||
if (flags & GRN_OBJ_KEY_VAR_SIZE) {
|
||||
entry_size = (uintptr_t)((grn_tiny_hash_entry *)0)->value + value_size;
|
||||
entry_size = offsetof(grn_tiny_hash_entry, value) + value_size;
|
||||
} else {
|
||||
if (key_size == sizeof(uint32_t)) {
|
||||
entry_size = (uintptr_t)((grn_plain_hash_entry *)0)->value + value_size;
|
||||
entry_size = offsetof(grn_plain_hash_entry, value) + value_size;
|
||||
} else {
|
||||
entry_size = (uintptr_t)((grn_rich_hash_entry *)0)->key_and_value
|
||||
entry_size = offsetof(grn_rich_hash_entry, key_and_value)
|
||||
+ key_size + value_size;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue