commit 4a4d9ab577aeff2c34259bcb82e7dd33034e2bc6
Author: Carl Simonson <carl.simonson@garmin.com>
Date: Tue Apr 12 15:12:10 2011 -0500
regex: Fix up code that uses exceptions
Some places in the boost::regex library did not safely guard uses of
exceptions with checks to see if exceptions were enabled.
diff --git a/boost/regex/v4/basic_regex.hpp b/boost/regex/v4/basic_regex.hpp
index 04c7bb3..cb51af7 100644
a
|
b
|
|
1 | 1 | /* |
2 | 2 | * |
3 | | * Copyright (c) 1998-2004 |
4 | | * John Maddock |
| 3 | * Copyright (c) 1998-2004 John Maddock |
| 4 | * Copyright 2011 Carl Simonson |
5 | 5 | * |
6 | 6 | * Distributed under the Boost Software License, Version 1.0. |
7 | 7 | * (See accompanying file LICENSE_1_0.txt or copy at |
… |
… |
public:
|
234 | 234 | std::pair<const_iterator, const_iterator> BOOST_REGEX_CALL subexpression(std::size_t n)const |
235 | 235 | { |
236 | 236 | if(n == 0) |
237 | | throw std::out_of_range("0 is not a valid subexpression index."); |
| 237 | boost::throw_exception(std::out_of_range("0 is not a valid subexpression index.")); |
238 | 238 | const std::pair<std::size_t, std::size_t>& pi = this->m_subs.at(n - 1); |
239 | 239 | std::pair<const_iterator, const_iterator> p(expression() + pi.first, expression() + pi.second); |
240 | 240 | return p; |
… |
… |
public:
|
487 | 487 | std::pair<const_iterator, const_iterator> BOOST_REGEX_CALL subexpression(std::size_t n)const |
488 | 488 | { |
489 | 489 | if(!m_pimpl.get()) |
490 | | throw std::logic_error("Can't access subexpressions in an invalid regex."); |
| 490 | boost::throw_exception(std::logic_error("Can't access subexpressions in an invalid regex.")); |
491 | 491 | return m_pimpl->subexpression(n); |
492 | 492 | } |
493 | 493 | const_iterator BOOST_REGEX_CALL begin()const |
diff --git a/boost/regex/v4/cpp_regex_traits.hpp b/boost/regex/v4/cpp_regex_traits.hpp
index cd22bd8..c781d74 100644
a
|
b
|
|
1 | 1 | /* |
2 | 2 | * |
3 | | * Copyright (c) 2004 |
4 | | * John Maddock |
| 3 | * Copyright (c) 2004 John Maddock |
| 4 | * Copyright 2011 Carl Simonson |
5 | 5 | * |
6 | 6 | * Use, modification and distribution are subject to the |
7 | 7 | * Boost Software License, Version 1.0. (See accompanying file |
… |
… |
typename cpp_regex_traits_implementation<charT>::string_type
|
511 | 511 | // however at least one std lib will always throw |
512 | 512 | // std::bad_alloc for certain arguments... |
513 | 513 | // |
| 514 | #ifndef BOOST_NO_EXCEPTIONS |
514 | 515 | try{ |
| 516 | #endif |
515 | 517 | // |
516 | 518 | // What we do here depends upon the format of the sort key returned by |
517 | 519 | // sort key returned by this->transform: |
… |
… |
typename cpp_regex_traits_implementation<charT>::string_type
|
546 | 548 | result.erase(i); |
547 | 549 | break; |
548 | 550 | } |
| 551 | #ifndef BOOST_NO_EXCEPTIONS |
549 | 552 | }catch(...){} |
| 553 | #endif |
550 | 554 | while(result.size() && (charT(0) == *result.rbegin())) |
551 | 555 | result.erase(result.size() - 1); |
552 | 556 | if(result.empty()) |
… |
… |
typename cpp_regex_traits_implementation<charT>::string_type
|
576 | 580 | // std::bad_alloc for certain arguments... |
577 | 581 | // |
578 | 582 | string_type result; |
| 583 | #ifndef BOOST_NO_EXCEPTIONS |
579 | 584 | try{ |
| 585 | #endif |
580 | 586 | result = this->m_pcollate->transform(p1, p2); |
581 | 587 | // |
582 | 588 | // Borland's STLPort version returns a NULL-terminated |
… |
… |
typename cpp_regex_traits_implementation<charT>::string_type
|
593 | 599 | result.erase(result.size() - 1); |
594 | 600 | #endif |
595 | 601 | BOOST_ASSERT(std::find(result.begin(), result.end(), charT(0)) == result.end()); |
| 602 | #ifndef BOOST_NO_EXCEPTIONS |
596 | 603 | } |
597 | 604 | catch(...) |
598 | 605 | { |
599 | 606 | } |
| 607 | #endif |
600 | 608 | return result; |
601 | 609 | } |
602 | 610 | |