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

Bug when starting with empty varray #2

Open
nikolaushuber opened this issue Sep 12, 2024 · 1 comment
Open

Bug when starting with empty varray #2

nikolaushuber opened this issue Sep 12, 2024 · 1 comment

Comments

@nikolaushuber
Copy link

The following example program seems to illustrate a bug when starting with an empty varray:

open Varray
let t = empty ( )
push_back t '.'
pop_front t

Interestingly, the behaviour seems to depend on the particular platform this is running on. On my MacBook with M2 ARM the above program results in a segmentation fault. On my Intel MacBook it returns a character, however, it is not the one previously pushed and it also changes each time the program is run.

This was found with an upcoming feature in ortac/qcheck-stm

@edwintorok
Copy link

edwintorok commented Dec 26, 2024

FWIW I get an assertion failure in utop, it looks like t.length is 0 in pop_front in circular.ml. Apparently push_back_new never updates t.first. push_front works.

Are you running with assertions off when you get the segfault?

This fixes the assertion failure, but I don't know enough about how varray works to know whether this change is correct or whether it'd need to also be done in other places (if you found this using property testing, then property testing could probably be used to find internal invariant failures like this):

diff --git a/src/root.ml b/src/root.ml
index 8fef9be..b2bb377 100644
--- a/src/root.ml
+++ b/src/root.ml
@@ -100,6 +100,7 @@ module Make (V : Varray_sig.TIER)
 
   let create_child ~lc t i x =
     let row = V.make ~lc 1 x in
+    if i = 0 then t.first <- row;
     Buffer.set ~lc t.rows i row
 
   let initialize ~lc t =

It looks like the dune file in varray turns off assertions in release mode (which seems like a bad idea when running tests!).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants