feat(fuzz)+fix: add schema fuzz testing and fix some bugs

This commit is contained in:
Levy A. 2025-06-04 23:18:37 -03:00
parent 54e8e7f097
commit 01a680b69e
5 changed files with 370 additions and 45 deletions

View file

@ -206,15 +206,7 @@ pub fn translate_inner(
name: table_name.clone(),
});
program.cursor_loop(cursor_id, |program| {
let rowid = program.alloc_register();
// FIXME: Handle tables without rowid.
program.emit_insn(Insn::RowId {
cursor_id,
dest: rowid,
});
program.cursor_loop(cursor_id, |program, rowid| {
let first_column = program.alloc_registers(column_count);
let mut iter = first_column;
@ -340,14 +332,7 @@ pub fn translate_inner(
name: sqlite_schema.name.clone(),
});
program.cursor_loop(cursor_id, |program| {
let rowid = program.alloc_register();
program.emit_insn(Insn::RowId {
cursor_id,
dest: rowid,
});
program.cursor_loop(cursor_id, |program, rowid| {
let first_column = program.alloc_registers(5);
for i in 0..5 {
@ -425,14 +410,7 @@ pub fn translate_inner(
name: sqlite_schema.name.clone(),
});
program.cursor_loop(cursor_id, |program| {
let rowid = program.alloc_register();
program.emit_insn(Insn::RowId {
cursor_id,
dest: rowid,
});
program.cursor_loop(cursor_id, |program, rowid| {
let first_column = program.alloc_registers(5);
for i in 0..5 {

View file

@ -774,7 +774,7 @@ impl ProgramBuilder {
}
#[inline]
pub fn cursor_loop(&mut self, cursor_id: CursorID, f: impl Fn(&mut ProgramBuilder)) {
pub fn cursor_loop(&mut self, cursor_id: CursorID, f: impl Fn(&mut ProgramBuilder, usize)) {
let loop_start = self.allocate_label();
let loop_end = self.allocate_label();
@ -784,7 +784,19 @@ impl ProgramBuilder {
});
self.preassign_label_to_next_insn(loop_start);
f(self);
let rowid = self.alloc_register();
self.emit_insn(Insn::RowId {
cursor_id,
dest: rowid,
});
self.emit_insn(Insn::IsNull {
reg: rowid,
target_pc: loop_end,
});
f(self, rowid);
self.emit_insn(Insn::Next {
cursor_id,