comparison src/regexp_nfa.c @ 27000:8c0730eca2ce v8.2.4029

patch 8.2.4029: debugging NFA regexp my crash, cached indent may be wrong Commit: https://github.com/vim/vim/commit/b2d85e3784ac89f5209489844c1ee0f54d117abb Author: Bram Moolenaar <Bram@vim.org> Date: Fri Jan 7 16:55:32 2022 +0000 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)
author Bram Moolenaar <Bram@vim.org>
date Fri, 07 Jan 2022 18:00:04 +0100
parents ac75c145f0a9
children fb4c30606b4a
comparison
equal deleted inserted replaced
26999:aba0728a28d9 27000:8c0730eca2ce
2883 { 2883 {
2884 int last = indent->ga_len - 3; 2884 int last = indent->ga_len - 3;
2885 char_u save[2]; 2885 char_u save[2];
2886 2886
2887 STRNCPY(save, &p[last], 2); 2887 STRNCPY(save, &p[last], 2);
2888 STRNCPY(&p[last], "+-", 2); 2888 memcpy(&p[last], "+-", 2);
2889 fprintf(debugf, " %s", p); 2889 fprintf(debugf, " %s", p);
2890 STRNCPY(&p[last], save, 2); 2890 STRNCPY(&p[last], save, 2);
2891 } 2891 }
2892 else 2892 else
2893 fprintf(debugf, " %s", p); 2893 fprintf(debugf, " %s", p);
4290 return TRUE; 4290 return TRUE;
4291 } 4291 }
4292 4292
4293 #ifdef ENABLE_LOG 4293 #ifdef ENABLE_LOG
4294 static void 4294 static void
4295 open_debug_log(int result)
4296 {
4297 log_fd = fopen(NFA_REGEXP_RUN_LOG, "a");
4298 if (log_fd == NULL)
4299 {
4300 emsg(_(e_log_open_failed));
4301 log_fd = stderr;
4302 }
4303
4304 fprintf(log_fd, "****************************\n");
4305 fprintf(log_fd, "FINISHED RUNNING nfa_regmatch() recursively\n");
4306 fprintf(log_fd, "MATCH = %s\n", result == TRUE ? "OK" : result == MAYBE
4307 ? "MAYBE" : "FALSE");
4308 fprintf(log_fd, "****************************\n");
4309 }
4310
4311 static void
4295 report_state(char *action, 4312 report_state(char *action,
4296 regsub_T *sub, 4313 regsub_T *sub,
4297 nfa_state_T *state, 4314 nfa_state_T *state,
4298 int lid, 4315 int lid,
4299 nfa_pim_T *pim) 4316 nfa_pim_T *pim)
4305 else if (REG_MULTI) 4322 else if (REG_MULTI)
4306 col = sub->list.multi[0].start_col; 4323 col = sub->list.multi[0].start_col;
4307 else 4324 else
4308 col = (int)(sub->list.line[0].start - rex.line); 4325 col = (int)(sub->list.line[0].start - rex.line);
4309 nfa_set_code(state->c); 4326 nfa_set_code(state->c);
4327 if (log_fd == NULL)
4328 open_debug_log(MAYBE);
4329
4310 fprintf(log_fd, "> %s state %d to list %d. char %d: %s (start col %d)%s\n", 4330 fprintf(log_fd, "> %s state %d to list %d. char %d: %s (start col %d)%s\n",
4311 action, abs(state->id), lid, state->c, code, col, 4331 action, abs(state->id), lid, state->c, code, col,
4312 pim_info(pim)); 4332 pim_info(pim));
4313 } 4333 }
4314 #endif 4334 #endif
5428 rex.nfa_listid = save_nfa_listid; 5448 rex.nfa_listid = save_nfa_listid;
5429 } 5449 }
5430 nfa_endp = save_nfa_endp; 5450 nfa_endp = save_nfa_endp;
5431 5451
5432 #ifdef ENABLE_LOG 5452 #ifdef ENABLE_LOG
5433 log_fd = fopen(NFA_REGEXP_RUN_LOG, "a"); 5453 open_debug_log(result);
5434 if (log_fd != NULL)
5435 {
5436 fprintf(log_fd, "****************************\n");
5437 fprintf(log_fd, "FINISHED RUNNING nfa_regmatch() recursively\n");
5438 fprintf(log_fd, "MATCH = %s\n", result == TRUE ? "OK" : "FALSE");
5439 fprintf(log_fd, "****************************\n");
5440 }
5441 else
5442 {
5443 emsg(_(e_log_open_failed));
5444 log_fd = stderr;
5445 }
5446 #endif 5454 #endif
5447 5455
5448 return result; 5456 return result;
5449 } 5457 }
5450 5458
5773 if (list[0].t == NULL || list[1].t == NULL) 5781 if (list[0].t == NULL || list[1].t == NULL)
5774 goto theend; 5782 goto theend;
5775 5783
5776 #ifdef ENABLE_LOG 5784 #ifdef ENABLE_LOG
5777 log_fd = fopen(NFA_REGEXP_RUN_LOG, "a"); 5785 log_fd = fopen(NFA_REGEXP_RUN_LOG, "a");
5778 if (log_fd != NULL) 5786 if (log_fd == NULL)
5779 {
5780 fprintf(log_fd, "**********************************\n");
5781 nfa_set_code(start->c);
5782 fprintf(log_fd, " RUNNING nfa_regmatch() starting with state %d, code %s\n",
5783 abs(start->id), code);
5784 fprintf(log_fd, "**********************************\n");
5785 }
5786 else
5787 { 5787 {
5788 emsg(_(e_log_open_failed)); 5788 emsg(_(e_log_open_failed));
5789 log_fd = stderr; 5789 log_fd = stderr;
5790 } 5790 }
5791 fprintf(log_fd, "**********************************\n");
5792 nfa_set_code(start->c);
5793 fprintf(log_fd, " RUNNING nfa_regmatch() starting with state %d, code %s\n",
5794 abs(start->id), code);
5795 fprintf(log_fd, "**********************************\n");
5791 #endif 5796 #endif
5792 5797
5793 thislist = &list[0]; 5798 thislist = &list[0];
5794 thislist->n = 0; 5799 thislist->n = 0;
5795 thislist->has_pim = FALSE; 5800 thislist->has_pim = FALSE;
6917 { 6922 {
6918 int c = t->state->c; 6923 int c = t->state->c;
6919 6924
6920 #ifdef DEBUG 6925 #ifdef DEBUG
6921 if (c < 0) 6926 if (c < 0)
6922 siemsg("INTERNAL: Negative state char: %ld", c); 6927 siemsg("INTERNAL: Negative state char: %ld", (long)c);
6923 #endif 6928 #endif
6924 result = (c == curc); 6929 result = (c == curc);
6925 6930
6926 if (!result && rex.reg_ic) 6931 if (!result && rex.reg_ic)
6927 result = MB_CASEFOLD(c) == MB_CASEFOLD(curc); 6932 result = MB_CASEFOLD(c) == MB_CASEFOLD(curc);