Skip to content

Commit

Permalink
fix potential crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
krangelov committed Sep 3, 2024
1 parent c519d4b commit d43d2cb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/runtime/c/pgf/expr.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,17 @@ PgfType PgfDBUnmarshaller::dtyp(size_t n_hypos, PgfTypeHypo *hypos,
ref<PgfDTyp> ty =
PgfDB::malloc<PgfDTyp>(cat->size+1);
memcpy(&ty->name, cat, sizeof(PgfText)+cat->size+1);
ty->hypos = vector<PgfHypo>::alloc(n_hypos);
vector<PgfHypo> new_hypos = vector<PgfHypo>::alloc(n_hypos);
ty->hypos = new_hypos;
for (size_t i = 0; i < n_hypos; i++) {
ref<PgfHypo> hypo = ty->hypos.elem(i);
hypo->bind_type = hypos[i].bind_type;
hypo->cid = textdup_db(hypos[i].cid);
PgfType type = m->match_type(this, hypos[i].type);
hypo->type = type;
}
ty->exprs = vector<PgfExpr>::alloc(n_exprs);
vector<PgfExpr> new_exprs = vector<PgfExpr>::alloc(n_exprs);
ty->exprs = new_exprs;
for (size_t i = 0; i < n_exprs; i++) {
PgfExpr expr = m->match_expr(this, exprs[i]);
ty->exprs[i] = expr;
Expand Down
3 changes: 2 additions & 1 deletion src/runtime/c/pgf/pgf.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1572,7 +1572,8 @@ void pgf_create_category(PgfDB *db, PgfRevision revision,

ref<PgfPGF> pgf = db->revision2pgf(revision);
ref<PgfAbsCat> abscat = PgfDB::malloc<PgfAbsCat>(name->size+1);
abscat->context = vector<PgfHypo>::alloc(n_hypos);
vector<PgfHypo> new_context = vector<PgfHypo>::alloc(n_hypos);
abscat->context = new_context;
abscat->prob = prob;
memcpy(&abscat->name, name, sizeof(PgfText)+name->size+1);

Expand Down

0 comments on commit d43d2cb

Please sign in to comment.