Mercurial > vim
comparison src/regexp_nfa.c @ 15812:3808b583889e v8.1.0913
patch 8.1.0913: CI crashes when running out of memory
commit https://github.com/vim/vim/commit/688b3983d8b321e0d32dd51914fa474a0988daf6
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Feb 13 21:47:36 2019 +0100
patch 8.1.0913: CI crashes when running out of memory
Problem: CI crashes when running out of memory.
Solution: Apply 'maxmempattern' also to new regexp engine.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 13 Feb 2019 22:00:07 +0100 |
parents | 6a4e9d9f1d66 |
children | 6733b8b1caf3 |
comparison
equal
deleted
inserted
replaced
15811:efcccd2b7f46 | 15812:3808b583889e |
---|---|
4443 * positions. */ | 4443 * positions. */ |
4444 if (has_state_with_pos(l, state, subs, pim)) | 4444 if (has_state_with_pos(l, state, subs, pim)) |
4445 goto skip_add; | 4445 goto skip_add; |
4446 } | 4446 } |
4447 | 4447 |
4448 /* When there are backreferences or PIMs the number of states may | 4448 // When there are backreferences or PIMs the number of states may |
4449 * be (a lot) bigger than anticipated. */ | 4449 // be (a lot) bigger than anticipated. |
4450 if (l->n == l->len) | 4450 if (l->n == l->len) |
4451 { | 4451 { |
4452 int newlen = l->len * 3 / 2 + 50; | 4452 int newlen = l->len * 3 / 2 + 50; |
4453 size_t newsize = newlen * sizeof(nfa_thread_T); | |
4453 nfa_thread_T *newt; | 4454 nfa_thread_T *newt; |
4454 | 4455 |
4456 if ((long)(newsize >> 10) >= p_mmp) | |
4457 { | |
4458 emsg(_(e_maxmempat)); | |
4459 --depth; | |
4460 return NULL; | |
4461 } | |
4455 if (subs != &temp_subs) | 4462 if (subs != &temp_subs) |
4456 { | 4463 { |
4457 /* "subs" may point into the current array, need to make a | 4464 /* "subs" may point into the current array, need to make a |
4458 * copy before it becomes invalid. */ | 4465 * copy before it becomes invalid. */ |
4459 copy_sub(&temp_subs.norm, &subs->norm); | 4466 copy_sub(&temp_subs.norm, &subs->norm); |
4462 copy_sub(&temp_subs.synt, &subs->synt); | 4469 copy_sub(&temp_subs.synt, &subs->synt); |
4463 #endif | 4470 #endif |
4464 subs = &temp_subs; | 4471 subs = &temp_subs; |
4465 } | 4472 } |
4466 | 4473 |
4467 newt = vim_realloc(l->t, newlen * sizeof(nfa_thread_T)); | 4474 newt = vim_realloc(l->t, newsize); |
4468 if (newt == NULL) | 4475 if (newt == NULL) |
4469 { | 4476 { |
4470 // out of memory | 4477 // out of memory |
4471 --depth; | 4478 --depth; |
4472 return NULL; | 4479 return NULL; |
4783 if (l->n + count - 1 >= l->len) | 4790 if (l->n + count - 1 >= l->len) |
4784 { | 4791 { |
4785 /* not enough space to move the new states, reallocate the list | 4792 /* not enough space to move the new states, reallocate the list |
4786 * and move the states to the right position */ | 4793 * and move the states to the right position */ |
4787 int newlen = l->len * 3 / 2 + 50; | 4794 int newlen = l->len * 3 / 2 + 50; |
4795 size_t newsize = newlen * sizeof(nfa_thread_T); | |
4788 nfa_thread_T *newl; | 4796 nfa_thread_T *newl; |
4789 | 4797 |
4790 newl = (nfa_thread_T *)alloc(newlen * sizeof(nfa_thread_T)); | 4798 if ((long)(newsize >> 10) >= p_mmp) |
4799 { | |
4800 emsg(_(e_maxmempat)); | |
4801 return NULL; | |
4802 } | |
4803 newl = (nfa_thread_T *)alloc(newsize); | |
4791 if (newl == NULL) | 4804 if (newl == NULL) |
4792 return NULL; | 4805 return NULL; |
4793 l->len = newlen; | 4806 l->len = newlen; |
4794 mch_memmove(&(newl[0]), | 4807 mch_memmove(&(newl[0]), |
4795 &(l->t[0]), | 4808 &(l->t[0]), |