comparison src/regexp_nfa.c @ 20677:ab0dc036f586 v8.2.0892

patch 8.2.0892: ubsan warns for undefined behavior Commit: https://github.com/vim/vim/commit/c5acc0f7fed6b061d994fc5ac660dcc0312750bd Author: Bram Moolenaar <Bram@vim.org> Date: Wed Jun 3 18:55:38 2020 +0200 patch 8.2.0892: ubsan warns for undefined behavior Problem: Ubsan warns for undefined behavior. Solution: Use unsigned instead of signed variable. (Dominique Pelle, closes #6193)
author Bram Moolenaar <Bram@vim.org>
date Wed, 03 Jun 2020 19:00:04 +0200
parents aadd1cae2ff5
children 097f5b5c907b
comparison
equal deleted inserted replaced
20676:96e5c3e65d20 20677:ab0dc036f586
244 }; 244 };
245 245
246 static char_u e_nul_found[] = N_("E865: (NFA) Regexp end encountered prematurely"); 246 static char_u e_nul_found[] = N_("E865: (NFA) Regexp end encountered prematurely");
247 static char_u e_misplaced[] = N_("E866: (NFA regexp) Misplaced %c"); 247 static char_u e_misplaced[] = N_("E866: (NFA regexp) Misplaced %c");
248 static char_u e_ill_char_class[] = N_("E877: (NFA regexp) Invalid character class: %d"); 248 static char_u e_ill_char_class[] = N_("E877: (NFA regexp) Invalid character class: %d");
249 static char_u e_value_too_large[] = N_("E951: \\% value too large");
249 250
250 // Variables only used in nfa_regcomp() and descendants. 251 // Variables only used in nfa_regcomp() and descendants.
251 static int nfa_re_flags; // re_flags passed to nfa_regcomp() 252 static int nfa_re_flags; // re_flags passed to nfa_regcomp()
252 static int *post_start; // holds the postfix form of r.e. 253 static int *post_start; // holds the postfix form of r.e.
253 static int *post_end; 254 static int *post_end;
1539 break; 1540 break;
1540 } 1541 }
1541 1542
1542 default: 1543 default:
1543 { 1544 {
1544 long n = 0; 1545 long_u n = 0;
1545 int cmp = c; 1546 int cmp = c;
1546 1547
1547 if (c == '<' || c == '>') 1548 if (c == '<' || c == '>')
1548 c = getchr(); 1549 c = getchr();
1549 while (VIM_ISDIGIT(c)) 1550 while (VIM_ISDIGIT(c))
1550 { 1551 {
1551 n = n * 10 + (c - '0'); 1552 long_u tmp = n * 10 + (c - '0');
1553
1554 if (tmp < n)
1555 {
1556 // overflow.
1557 emsg(_(e_value_too_large));
1558 return FAIL;
1559 }
1560 n = tmp;
1552 c = getchr(); 1561 c = getchr();
1553 } 1562 }
1554 if (c == 'l' || c == 'c' || c == 'v') 1563 if (c == 'l' || c == 'c' || c == 'v')
1555 { 1564 {
1556 int limit = INT_MAX; 1565 long_u limit = INT_MAX;
1557 1566
1558 if (c == 'l') 1567 if (c == 'l')
1559 { 1568 {
1560 // \%{n}l \%{n}<l \%{n}>l 1569 // \%{n}l \%{n}<l \%{n}>l
1561 EMIT(cmp == '<' ? NFA_LNUM_LT : 1570 EMIT(cmp == '<' ? NFA_LNUM_LT :
1574 cmp == '>' ? NFA_VCOL_GT : NFA_VCOL); 1583 cmp == '>' ? NFA_VCOL_GT : NFA_VCOL);
1575 limit = INT_MAX / MB_MAXBYTES; 1584 limit = INT_MAX / MB_MAXBYTES;
1576 } 1585 }
1577 if (n >= limit) 1586 if (n >= limit)
1578 { 1587 {
1579 emsg(_("E951: \\% value too large")); 1588 emsg(_(e_value_too_large));
1580 return FAIL; 1589 return FAIL;
1581 } 1590 }
1582 EMIT((int)n); 1591 EMIT((int)n);
1583 break; 1592 break;
1584 } 1593 }