patch 8.2.4029: debugging NFA regexp my crash, cached indent may be wrong

Problem:    Debugging NFA regexp my crash, cached indent may be wrong.
Solution:   Fix some debug warnings in the NFA regexp code.  Make sure log_fd
            is set when used.  Fix breakindent and indent caching. (Christian
            Brabandt, closes #9482)
diff --git a/src/indent.c b/src/indent.c
index 4a8b367..b74bae6 100644
--- a/src/indent.c
+++ b/src/indent.c
@@ -915,13 +915,15 @@
     win_T	*wp,
     char_u	*line) // start of the line
 {
-    static int	    prev_indent = 0;  // cached indent value
-    static long	    prev_ts     = 0L; // cached tabstop value
-    static char_u   *prev_line = NULL; // cached pointer to line
+    static int	    prev_indent = 0;	// cached indent value
+    static long	    prev_ts     = 0L;	// cached tabstop value
+    static char_u   *prev_line = NULL;	// cached pointer to line
     static varnumber_T prev_tick = 0;   // changedtick of cached value
 # ifdef FEAT_VARTABS
-    static int      *prev_vts = NULL;    // cached vartabs values
+    static int      *prev_vts = NULL;   // cached vartabs values
 # endif
+    static int      prev_list = 0;	// cached list value
+    static int      prev_listopt = 0;	// cached w_p_briopt_list value
     int		    bri = 0;
     // window width minus window margin space, i.e. what rests for text
     const int	    eff_wwidth = wp->w_width
@@ -929,9 +931,10 @@
 				&& (vim_strchr(p_cpo, CPO_NUMCOL) == NULL)
 						? number_width(wp) + 1 : 0);
 
-    // used cached indent, unless pointer or 'tabstop' changed
+    // used cached indent, unless line, 'tabstop' or briopt_list changed
     if (prev_line != line || prev_ts != wp->w_buffer->b_p_ts
 	    || prev_tick != CHANGEDTICK(wp->w_buffer)
+	    || prev_listopt != wp->w_briopt_list
 # ifdef FEAT_VARTABS
 	    || prev_vts != wp->w_buffer->b_p_vts_array
 # endif
@@ -949,6 +952,28 @@
 	prev_indent = get_indent_str(line,
 				     (int)wp->w_buffer->b_p_ts, wp->w_p_list);
 # endif
+	prev_listopt = wp->w_briopt_list;
+	// add additional indent for numbered lists
+	if (wp->w_briopt_list != 0)
+	{
+	    regmatch_T	    regmatch;
+
+	    regmatch.regprog = vim_regcomp(curbuf->b_p_flp,
+				       RE_MAGIC + RE_STRING + RE_AUTO + RE_STRICT);
+
+	    if (regmatch.regprog != NULL)
+	    {
+		regmatch.rm_ic = FALSE;
+		if (vim_regexec(&regmatch, line, 0))
+		{
+		    if (wp->w_briopt_list > 0)
+			prev_list = wp->w_briopt_list;
+		    else
+			prev_list = (*regmatch.endp - *regmatch.startp);
+		}
+		vim_regfree(regmatch.regprog);
+	    }
+	}
     }
     bri = prev_indent + wp->w_briopt_shift;
 
@@ -958,22 +983,10 @@
     // add additional indent for numbered lists
     if (wp->w_briopt_list != 0)
     {
-	regmatch_T	    regmatch;
-
-	regmatch.regprog = vim_regcomp(curbuf->b_p_flp,
-				   RE_MAGIC + RE_STRING + RE_AUTO + RE_STRICT);
-	if (regmatch.regprog != NULL)
-	{
-	    regmatch.rm_ic = FALSE;
-	    if (vim_regexec(&regmatch, line, 0))
-	    {
-		if (wp->w_briopt_list > 0)
-		    bri += wp->w_briopt_list;
-		else
-		    bri = (*regmatch.endp - *regmatch.startp);
-	    }
-	    vim_regfree(regmatch.regprog);
-	}
+	if (wp->w_briopt_list > 0)
+	    bri += prev_list;
+	else
+	    bri = prev_list;
     }
 
     // indent minus the length of the showbreak string