Skip to content

Commit

Permalink
FIXED: #1277 crash in trie_gen_compiled/3.
Browse files Browse the repository at this point in the history
  • Loading branch information
JanWielemaker committed May 12, 2024
1 parent f9809d3 commit 3a43aef
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/pl-trie.c
Original file line number Diff line number Diff line change
Expand Up @@ -3042,21 +3042,28 @@ compile_trie(DECL_LD Definition def, trie *trie)
{ trie_compile_state state;
Clause cl;
ClauseRef cref;
fid_t fid;

init_trie_compile_state(&state, trie);
add_vmi(&state, def->functor->arity == 2 ? T_TRIE_GEN2 : T_TRIE_GEN3);
if ( compile_trie_node(&trie->root, &state) &&
fixup_last_fail(&state) &&
create_trie_clause(def, &cl, &state) )
{ cref = assertDefinition(def, cl, CL_END);
if ( cref )
{ dbref = lookup_clref(cref->value.clause);
if ( !COMPARE_AND_SWAP_ATOM(&trie->clause, 0, dbref) )
{ PL_unregister_atom(dbref);
retractClauseDefinition(def, cref->value.clause, FALSE);
goto retry;
if ( (fid=PL_open_foreign_frame()) )
{ if ( compile_trie_node(&trie->root, &state) &&
fixup_last_fail(&state) &&
create_trie_clause(def, &cl, &state) )
{ cref = assertDefinition(def, cl, CL_END);
if ( cref )
{ dbref = lookup_clref(cref->value.clause);
if ( !COMPARE_AND_SWAP_ATOM(&trie->clause, 0, dbref) )
{ PL_unregister_atom(dbref);
retractClauseDefinition(def, cref->value.clause, FALSE);
PL_close_foreign_frame(fid);
goto retry;
}
}
}
PL_close_foreign_frame(fid);
} else
{ dbref = ATOM_error;
}
assert(state.else_loc == 0);
clean_trie_compile_state(&state);
Expand Down
2 changes: 2 additions & 0 deletions src/pl-vmi.c
Original file line number Diff line number Diff line change
Expand Up @@ -5961,6 +5961,8 @@ VMI(S_TRIE_GEN, 0, 0, ())
SAVE_REGISTERS(QID);
dbref = compile_trie(FR->predicate, t);
LOAD_REGISTERS(QID);
if ( dbref == ATOM_error )
THROW_EXCEPTION;
}

if ( dbref == ATOM_fail )
Expand Down

0 comments on commit 3a43aef

Please sign in to comment.