*** generic/regcomp.c~	Sun Sep  6 16:29:00 2015
--- generic/regcomp.c	Wed Sep  9 19:00:46 2015
***************
*** 593,605 ****
  		break;
  	    }
  	}
  	if (b != NULL && s->tmp == NULL) {
! 	    /*
! 	     * Must be split if not already in the list (fixes bugs 505048,
! 	     * 230589, 840258, 504785).
! 	     */
! 
! 	    s->tmp = slist;
  	    slist = s;
  	}
      }
--- 593,607 ----
  		break;
  	    }
  	}
+  
+ 	/*
+ 	 * We want to mark states as being in the list already by having non
+ 	 * NULL tmp fields, but we can't just store the old slist value in tmp
+ 	 * because that doesn't work for the first such state.  Instead, the
+ 	 * first list entry gets its own address in tmp.
+ 	 */
  	if (b != NULL && s->tmp == NULL) {
! 	    s->tmp = (slist != NULL) ? slist : s;
  	    slist = s;
  	}
      }
***************
*** 620,626 ****
  		freearc(nfa, a);
  	    }
  	}
! 	s2 = s->tmp;
  	s->tmp = NULL;		/* clean up while we're at it */
      }
  }
--- 622,628 ----
  		freearc(nfa, a);
  	    }
  	}
! 	s2 = (s->tmp != s) ? s->tmp : NULL;
  	s->tmp = NULL;		/* clean up while we're at it */
      }
  }
