SQLite Forum

Assertion Failure "target>0 && target<=pParse->nMem"
Login

Assertion Failure "target>0 && target<=pParse->nMem"

(1) By Yu Liang (LY1598773890) on 2021-07-07 16:12:03

## Query

```
CREATE TABLE v0 ( v2, v3, v4 AS (v4 <= 0), v1, FOREIGN KEY ( v4, v1, v3, v2, v3, v1, v3, v4 ) REFERENCES t0);
PRAGMA foreign_key_check;
```

## Run on debug version

```
sqlite3.c:106136: sqlite3ExprCode: Assertion `target>0 && target<=pParse->nMem' failed.
```

## Run on non-debug version

```
Error: near line 2: generated column loop on "v4"
```

## Bisect

```
  1 BAD     2021-07-07 13:53:55 6b22f4e71dbc14c8
  2 BAD     2020-01-15 16:20:16 03b003c988d27f3a
  4 BAD     2019-12-14 19:55:31 a89b38605661e36d
  5 BAD     2019-11-16 23:47:40 51525f9c3235967b
  6 BAD     2019-10-30 18:50:08 2978b65ebe25eeab
  9 BAD     2019-10-29 01:26:24 591973217f1caf24
 10 BAD     2019-10-28 04:20:28 a1e1ba9145049491
 11 BAD     2019-10-27 22:22:24 6d1bbba9a004a249
 12 BAD     2019-10-26 23:51:44 5b4c0f2ddc6f324e CURRENT
  8 GOOD    2019-10-26 18:56:12 713fe86b8c9f3c9e
  7 GOOD    2019-10-23 21:00:40 1a6e009372cf9571
  3 GOOD    2019-10-11 14:21:48 bf875dc59909f9c2
```

(2) By Larry Brasfield (larrybr) on 2021-07-07 16:26:19 in reply to 1 [link]

Thanks for the report, and especially for the bisect!

(3) By Yu Liang (LY1598773890) on 2021-07-07 16:53:10 in reply to 2 [link]

Thanks for the prompt fix!

(4) By Richard Hipp (drh) on 2021-07-07 16:54:48 in reply to 1 [link]

This is a follow-up to [forum post a6b0c05277](/forumpost/a6b0c05277).

The original problem was that the code generator was not allocating
enough registers in the bytecode.  That was fixed by 
check-in [68db1ff9c44fa9c3](src:/info/68db1ff9c44fa9c3)
However, the increase in the number of registered allocated happened
too late for the assert() that you found in sqlite3ExprCode().  The
solution (check-in [7072404ad0267b8e](src:/info/7072404ad0267b8e)) is to
move the increase in the number of bytecode registers a little earlier.

Thanks for using Fossil and for running bisect.