trealla: number_chars/2 corrupts memory

Corruption is manifested by altering the variable names in answer substitutions.

ulrich@gupu:/tmp$ cat n0.pl 
:- use_module(library(clpz)).
:- set_prolog_flag(double_quotes,chars).

g([A,B,C,D]) :-
   member(A,"abcdefxABCDEF0"),
   member(B,"0123456789abcdefxABCDEFX 'n"),
   member(C,"0123456789abcdefxABCDEFX 'n"),
   member(D,"0123456789abcdefxABCDEFX '").
   
chs(Chs) :-
   g(Chs),
   catch(number_chars(_,Chs), error(_,_), Bad=true),
   ( Bad = false -> halt ; true ),
   Chs = ['F','A'|_].
ulrich@gupu:/tmp$ /opt/gupu/new-trealla/tpl -f n0.pl -g 'chs(Chs).'
   Chs = "FA00"
;  ... % press a
;  Chs = "FAEF"
;  Chs = "FAEX"
;  Chs = "FAE "
;   = "FAE'"
;   = "FAF0"
...

So out of a sudden, the name for variable Chs vanishes

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 31 (15 by maintainers)

Commits related to this issue

Most upvoted comments

Now:

ulrich@gupu:/tmp$ /opt/gupu/new-trealla/tpl -f
?- [n2],call_nth(g5chs(L),Nth),catch(number_chars(N,L),error(E,_),true),Nth>1870000,Nth mod 10^3=:=0.
   L = "-F8{F", Nth = 1871000, E = syntax_error(needs_operator)
;   = "-F97e",  = 1872000,  = syntax_error(incomplete),  = number_chars/2
;  ... .
?- 
ulrich@gupu:/tmp$ cat n2.pl
:- use_module(library(clpz)).

g5chs(Chs) :-
   VChs = "-+0123456789.abcdefxABCDEFX{}[](), %\n/*'\\n",
   A = (-),
   Chs = [A,B,C,D,E],
   member(A,VChs),
   member(B,VChs),
   member(C,VChs),
   member(D,VChs),
   member(E,VChs).

It now runs to the end (for me)…

;   = "nnn'", 1 = 3111694,  = syntax_error(unterminated_quoted_atom),  = syntax_error(unterminated_quoted_atom),  = number_chars/2
;   = "nnn\\", 1 = 3111695,  = syntax_error(incomplete),  = syntax_error(incomplete),  = number_chars/2
;   = "nnnn", 1 = 3111696,  = syntax_error(incomplete),  = syntax_error(incomplete),  = number_chars/2.
?-