diff options
author | Rémi Verschelde <remi@verschelde.fr> | 2016-04-18 13:50:52 +0200 |
---|---|---|
committer | Rémi Verschelde <remi@verschelde.fr> | 2016-04-18 13:50:52 +0200 |
commit | 336cbfa7b63721757874f0fc5c33ec5dd31c5076 (patch) | |
tree | ae12e3f16c391a98bb00f622ba869a962217a90f | |
parent | fd07ef07fa9058e3fc6c72c246a4db421336c346 (diff) | |
parent | 48b2dfab9f91bec2fd9a0fc94630e2dae51fbf11 (diff) |
Merge pull request #4364 from leezh/master
Fixed SEGFAULT in zero-reserved arrays in nrex. Fixes #4346
-rw-r--r-- | drivers/nrex/nrex.cpp | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/drivers/nrex/nrex.cpp b/drivers/nrex/nrex.cpp index ac19c71408..69e04285e3 100644 --- a/drivers/nrex/nrex.cpp +++ b/drivers/nrex/nrex.cpp @@ -68,9 +68,9 @@ class nrex_array { } - nrex_array(unsigned int size) - : _data(NREX_NEW_ARRAY(T, size)) - , _reserved(size) + nrex_array(unsigned int reserved) + : _data(NREX_NEW_ARRAY(T, reserved ? reserved : 1)) + , _reserved(reserved ? reserved : 1) , _size(0) { } @@ -87,6 +87,12 @@ class nrex_array void reserve(unsigned int size) { + if (size < _size) { + size = _size; + } + if (size == 0) { + size = 1; + } T* old = _data; _data = NREX_NEW_ARRAY(T, size); _reserved = size; @@ -207,8 +213,8 @@ struct nrex_search : str(str) , captures(captures) , end(0) + , lookahead_pos(lookahead) { - lookahead_pos.reserve(lookahead); } }; |