Commit 46bdd627 authored by Paul Eggert's avatar Paul Eggert
Browse files

dfa: avoid use of uninitialized constraint

* lib/dfa.c (merge_nfa_state): Do not initialize the constraint
to zero here.
(dfaoptimize): Do it here instead, via xcalloc.  This prevents the
use of an uninitialized constraint by later code when ! (flags[i]
& OPT_QUEUED) means merge_nfa_state was not called to initialize
the constraint.  Problem found by running 'valgrind src/grep -E
'(^| )*(a|b)*(c|d)*( |$)' < /dev/null' on Ubuntu 18.04.5 x86-64.
parent 5332a21b
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
2020-09-13  Paul Eggert  <eggert@cs.ucla.edu>
	dfa: avoid use of uninitialized constraint
	* lib/dfa.c (merge_nfa_state): Do not initialize the constraint
	to zero here.
	(dfaoptimize): Do it here instead, via xcalloc.  This prevents the
	use of an uninitialized constraint by later code when ! (flags[i]
	& OPT_QUEUED) means merge_nfa_state was not called to initialize
	the constraint.  Problem found by running 'valgrind src/grep -E
	'(^| )*(a|b)*(c|d)*( |$)' < /dev/null' on Ubuntu 18.04.5 x86-64.
	dfa: assume C99 in reorder_tokens
	* lib/dfa.c (reorder_tokens): Assume C99 and simplify.
+1 −3
Original line number Diff line number Diff line
@@ -2428,8 +2428,6 @@ merge_nfa_state (struct dfa *d, idx_t tindex, char *flags,
  position_set *follows = d->follows;
  idx_t nelem = 0;

  d->constraints[tindex] = 0;

  for (idx_t i = 0; i < follows[tindex].nelem; i++)
    {
      idx_t sindex = follows[tindex].elems[i].index;
@@ -2581,7 +2579,7 @@ dfaoptimize (struct dfa *d)
  position_set *merged = &merged0;
  alloc_position_set (merged, d->nleaves);

  d->constraints = xnmalloc (d->tindex, sizeof *d->constraints);
  d->constraints = xcalloc (d->tindex, sizeof *d->constraints);

  for (idx_t i = 0; i < d->tindex; i++)
    if (flags[i] & OPT_QUEUED)