Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sqlite_version() SQL function panics #560

Closed
penberg opened this issue Dec 27, 2024 · 2 comments
Closed

sqlite_version() SQL function panics #560

penberg opened this issue Dec 27, 2024 · 2 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@penberg
Copy link
Collaborator

penberg commented Dec 27, 2024

Limbo v0.0.10
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database
limbo> SELECT sqlite_version();
thread 'main' panicked at core/vdbe/mod.rs:2750:72:
index out of bounds: the len is 3 but the index is 3
stack backtrace:
   0: rust_begin_unwind
             at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf/library/std/src/panicking.rs:665:5
   1: core::panicking::panic_fmt
             at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf/library/core/src/panicking.rs:74:14
   2: core::panicking::panic_bounds_check
             at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf/library/core/src/panicking.rs:276:5
   3: <usize as core::slice::index::SliceIndex<[T]>>::index
             at /Users/penberg/.rustup/toolchains/1.83.0-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/slice/index.rs:301:10
   4: core::slice::index::<impl core::ops::index::Index<I> for [T]>::index
             at /Users/penberg/.rustup/toolchains/1.83.0-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/slice/index.rs:16:9
   5: <alloc::vec::Vec<T,A> as core::ops::index::Index<I>>::index
             at /Users/penberg/.rustup/toolchains/1.83.0-aarch64-apple-darwin/lib/rustlib/src/rust/library/alloc/src/vec/mod.rs:3323:9
   6: limbo_core::vdbe::Program::step
             at ./core/vdbe/mod.rs:2750:72
   7: limbo_core::Statement::step
             at ./core/lib.rs:378:22
   8: limbo_core::Rows::next_row
             at ./core/lib.rs:425:9
   9: limbo::app::Limbo::query
             at ./cli/app.rs:500:27
  10: limbo::app::Limbo::handle_input_line::{{closure}}
             at ./cli/app.rs:385:37
  11: core::iter::traits::iterator::Iterator::for_each::call::{{closure}}
             at /Users/penberg/.rustup/toolchains/1.83.0-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/iter/traits/iterator.rs:810:29
  12: core::iter::adapters::filter::filter_fold::{{closure}}
             at /Users/penberg/.rustup/toolchains/1.83.0-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/iter/adapters/filter.rs:79:44
  13: core::iter::adapters::map::map_fold::{{closure}}
             at /Users/penberg/.rustup/toolchains/1.83.0-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/iter/adapters/map.rs:88:21
  14: core::iter::traits::iterator::Iterator::fold
             at /Users/penberg/.rustup/toolchains/1.83.0-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/iter/traits/iterator.rs:2584:21
  15: <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::fold
             at /Users/penberg/.rustup/toolchains/1.83.0-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/iter/adapters/map.rs:128:9
  16: <core::iter::adapters::filter::Filter<I,P> as core::iter::traits::iterator::Iterator>::fold
             at /Users/penberg/.rustup/toolchains/1.83.0-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/iter/adapters/filter.rs:159:9
  17: core::iter::traits::iterator::Iterator::for_each
             at /Users/penberg/.rustup/toolchains/1.83.0-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/iter/traits/iterator.rs:813:9
  18: limbo::app::Limbo::handle_input_line
             at ./cli/app.rs:378:13
  19: limbo::main
             at ./cli/main.rs:20:31
  20: core::ops::function::FnOnce::call_once
             at /Users/penberg/.rustup/toolchains/1.83.0-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
@penberg penberg added bug Something isn't working help wanted Extra attention is needed labels Dec 27, 2024
@diegoreis42
Copy link
Contributor

diegoreis42 commented Dec 27, 2024

The error is happening here:

                Insn::Copy {
                    src_reg,
                    dst_reg,
                    amount,
                } => {
                    for i in 0..=*amount {
                        state.registers[*dst_reg + i] = state.registers[*src_reg + i].clone();
                    }
                    state.pc += 1;
                }

removing = in the range resolves it, but of course, breaks everything. Probably the error is in the creation of Insn vector.

EDIT: I founded the error! It is in the expression translation. I gonna add a test for this and open a PR.

penberg added a commit that referenced this issue Dec 27, 2024
#560
Changes to `translate_expr` function:
* [`core/translate/expr.rs`](diffhunk://#diff-
371865d5d7b8bcaed649413c687492e61e94f21387cd9b2c47d989a033888c8bL1558-
R1560): Changed the `amount` parameter in the `Insn::Copy` instruction
from `1` to `0`.
Enhancements to the testing framework:
* [`testing/scalar-functions.test`](diffhunk://#diff-
a046d58ab24eee8207f0ce3199f8d0a609edcef9c24b8ed7f242f7a60e6c1e61R812-
R815): Added a new test `do_execsql_test_regex` to validate that the
`sqlite_version` function returns a valid output.
* [`testing/tester.tcl`](diffhunk://#diff-
316cca92d85df3f78558cc3e60d7420c1fd19a23ecf2bbea534db93ab08ea3ecR29-
R45): Introduced a new procedure `do_execsql_test_regex` to support
regex-based validation of SQL outputs.

Closes #561
@penberg
Copy link
Collaborator Author

penberg commented Dec 29, 2024

Fixed by #561

@penberg penberg closed this as completed Dec 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants