kevinlawler / kona

Open-source implementation of the K programming language
ISC License
1.36k stars 138 forks source link

Segfault on dictionary update in do block #555

Closed tavmem closed 4 years ago

tavmem commented 4 years ago

This bug was also identified by adam.antonik@gmail.com

{p[`a]:1;do[1;p[`b]:2];p}[]

Causes a core dump

This bug was introduced by the commit made on April 3, 2016 attempting to fix issue #423: 'value error' for any defined variable.

tavmem commented 4 years ago

Adam also made the comment (in Kona-User)

... we're getting in to an unhappy loop on line 77 of km.c. 
We seem to be attemping to free an object that is has a 2-cycle in it.

Yes, I agree, however ... ... the base problem still does appear to be somewhere in src/p.c ... although the original 3 lines added on April 3, 2016 are no longer in the current codebase.

I tried using the version of src/p.c that existed on March 31. 2016 in the current codebase and then made whatever minimal changes to other files that were necessary to get a compilation. I get the correct result:

  {p[`a]:1;do[1;p[`b]:2];p}[]
.((`a;1;)
  (`b;2;))

Minimal changes (for compliation) were made in the following files modified: src/c.h modified: src/k.h modified: src/kc.h modified: src/kx.c modified: src/kx.c modified: src/p.h modified: src/v.h

src/km.c was not touched.

tavmem commented 4 years ago

The problem is somewhrere in the function I capture(S s,I n,I k,Im,Vw,Id,Klocals,K*dict,K func)

When I take the current codebase and only replace the function "capture" with the version from March 31, 2016: -- no other changes are necessary for a compilation to work. -- I get the correct result

tavmem commented 4 years ago

Not surprisingly, the problem is in the section for CS(MARK_NAME,