Minor fix to prevent creation of schemas with invalid types.
This commit is contained in:
parent
b3b3f14758
commit
4cd0f03b0a
@ -5,12 +5,6 @@ fn main() {
|
||||
const MAGAZINE :usize = 0x100;
|
||||
const MAGAZINE_ROW :usize = 0x101;
|
||||
|
||||
// define schema "Magazine Row"
|
||||
szun::Schema::with(vec![
|
||||
("Content", szun::natural()),
|
||||
("Quantity", szun::natural()),
|
||||
]).bind(MAGAZINE_ROW);
|
||||
|
||||
// define schema "Magazine"
|
||||
let magazine = szun::Schema::with(vec![
|
||||
("Capacity", szun::natural()),
|
||||
@ -19,6 +13,12 @@ fn main() {
|
||||
]);
|
||||
magazine.bind(MAGAZINE);
|
||||
|
||||
// define schema "Magazine Row"
|
||||
szun::Schema::with(vec![
|
||||
("Content", szun::natural()),
|
||||
("Quantity", szun::natural()),
|
||||
]).bind(MAGAZINE_ROW);
|
||||
|
||||
// create record "Magazine"
|
||||
let _data = szun::Record::with(MAGAZINE, vec![
|
||||
("Capacity", *szun::Natural::with(30)),
|
||||
|
@ -1250,6 +1250,10 @@ extern "C" size_t schema_bind(Reference addr, size_t id)
|
||||
|
||||
size_t type_id = *reinterpret_cast<size_t*>(rawlist_cell(object.data, sizeof(size_t), i));
|
||||
size_t size = type_size(type_id);
|
||||
|
||||
// fail if size is not valid
|
||||
if(size == 0) { return 0; }
|
||||
|
||||
size_t alignment = type_alignment(type_id);
|
||||
binding.alignment = std::max(alignment, binding.alignment);
|
||||
size_t position = ((binding.size + (alignment - 1)) & ~(alignment - 1));
|
||||
@ -1290,9 +1294,9 @@ extern "C" size_t schema_bind(Reference addr, size_t id)
|
||||
|
||||
// add binding to pool
|
||||
DB_SCHEMA.set(id, binding);
|
||||
return id;
|
||||
}
|
||||
|
||||
return id;
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern "C" bool schema_has(size_t id)
|
||||
|
Reference in New Issue
Block a user