Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r74964 - in branches/release: boost boost/regex boost/regex/v4 libs/regex libs/regex/src libs/regex/test libs/regex/test/regress libs/regex/test/unicode
From: john_at_[hidden]
Date: 2011-10-16 08:19:40


Author: johnmaddock
Date: 2011-10-16 08:19:37 EDT (Sun, 16 Oct 2011)
New Revision: 74964
URL: http://svn.boost.org/trac/boost/changeset/74964

Log:
Merge accumulated minor fixes from Trunk.
Added:
   branches/release/libs/regex/src/internals.hpp
      - copied unchanged from r74961, /trunk/libs/regex/src/internals.hpp
   branches/release/libs/regex/test/test_consolidated.cpp
      - copied unchanged from r74961, /trunk/libs/regex/test/test_consolidated.cpp
Properties modified:
   branches/release/boost/cregex.hpp (props changed)
   branches/release/boost/regex/ (props changed)
   branches/release/boost/regex.hpp (props changed)
   branches/release/libs/regex/ (props changed)
Text files modified:
   branches/release/boost/regex/icu.hpp | 16 ++++++++--------
   branches/release/boost/regex/v4/basic_regex_creator.hpp | 2 +-
   branches/release/boost/regex/v4/regex_format.hpp | 10 +++++++++-
   branches/release/libs/regex/src/c_regex_traits.cpp | 21 +--------------------
   branches/release/libs/regex/src/cregex.cpp | 17 +++++++++++++++--
   branches/release/libs/regex/src/fileiter.cpp | 10 ++++++++--
   branches/release/libs/regex/src/posix_api.cpp | 10 ++++++++--
   branches/release/libs/regex/src/wc_regex_traits.cpp | 21 +--------------------
   branches/release/libs/regex/src/wide_posix_api.cpp | 16 ++++++++--------
   branches/release/libs/regex/test/Jamfile.v2 | 2 ++
   branches/release/libs/regex/test/regress/test_perl_ex.cpp | 4 ++++
   branches/release/libs/regex/test/unicode/unicode_iterator_test.cpp | 2 +-
   12 files changed, 66 insertions(+), 65 deletions(-)

Modified: branches/release/boost/regex/icu.hpp
==============================================================================
--- branches/release/boost/regex/icu.hpp (original)
+++ branches/release/boost/regex/icu.hpp 2011-10-16 08:19:37 EDT (Sun, 16 Oct 2011)
@@ -251,7 +251,7 @@
                               const boost::mpl::int_<1>*)
 {
    typedef boost::u8_to_u32_iterator<InputIterator, UChar32> conv_type;
- return u32regex(conv_type(i), conv_type(j), opt);
+ return u32regex(conv_type(i, i, j), conv_type(j, i, j), opt);
 }
 
 template <class InputIterator>
@@ -261,7 +261,7 @@
                               const boost::mpl::int_<2>*)
 {
    typedef boost::u16_to_u32_iterator<InputIterator, UChar32> conv_type;
- return u32regex(conv_type(i), conv_type(j), opt);
+ return u32regex(conv_type(i, i, j), conv_type(j, i, j), opt);
 }
 
 template <class InputIterator>
@@ -282,7 +282,7 @@
    typedef boost::u8_to_u32_iterator<InputIterator, UChar32> conv_type;
    typedef std::vector<UChar32> vector_type;
    vector_type v;
- conv_type a(i), b(j);
+ conv_type a(i, i, j), b(j, i, j);
    while(a != b)
    {
       v.push_back(*a);
@@ -302,7 +302,7 @@
    typedef boost::u16_to_u32_iterator<InputIterator, UChar32> conv_type;
    typedef std::vector<UChar32> vector_type;
    vector_type v;
- conv_type a(i), b(j);
+ conv_type a(i, i, j), b(j, i, j);
    while(a != b)
    {
       v.push_back(*a);
@@ -425,7 +425,7 @@
    typedef match_results<conv_type> match_type;
    typedef typename match_type::allocator_type alloc_type;
    match_type what;
- bool result = ::boost::regex_match(conv_type(first), conv_type(last), what, e, flags);
+ bool result = ::boost::regex_match(conv_type(first, first, last), conv_type(last, first, last), what, e, flags);
    // copy results across to m:
    if(result) copy_results(m, what);
    return result;
@@ -441,7 +441,7 @@
    typedef match_results<conv_type> match_type;
    typedef typename match_type::allocator_type alloc_type;
    match_type what;
- bool result = ::boost::regex_match(conv_type(first), conv_type(last), what, e, flags);
+ bool result = ::boost::regex_match(conv_type(first, first, last), conv_type(last, first, last), what, e, flags);
    // copy results across to m:
    if(result) copy_results(m, what);
    return result;
@@ -600,7 +600,7 @@
    typedef match_results<conv_type> match_type;
    typedef typename match_type::allocator_type alloc_type;
    match_type what;
- bool result = ::boost::regex_search(conv_type(first), conv_type(last), what, e, flags, conv_type(base));
+ bool result = ::boost::regex_search(conv_type(first, first, last), conv_type(last, first, last), what, e, flags, conv_type(base));
    // copy results across to m:
    if(result) copy_results(m, what);
    return result;
@@ -617,7 +617,7 @@
    typedef match_results<conv_type> match_type;
    typedef typename match_type::allocator_type alloc_type;
    match_type what;
- bool result = ::boost::regex_search(conv_type(first), conv_type(last), what, e, flags, conv_type(base));
+ bool result = ::boost::regex_search(conv_type(first, first, last), conv_type(last, first, last), what, e, flags, conv_type(base));
    // copy results across to m:
    if(result) copy_results(m, what);
    return result;

Modified: branches/release/boost/regex/v4/basic_regex_creator.hpp
==============================================================================
--- branches/release/boost/regex/v4/basic_regex_creator.hpp (original)
+++ branches/release/boost/regex/v4/basic_regex_creator.hpp 2011-10-16 08:19:37 EDT (Sun, 16 Oct 2011)
@@ -1226,7 +1226,7 @@
                for(unsigned int i = 0; i < (1u << CHAR_BIT); ++i)
                {
                   charT c = static_cast<charT>(i);
- if(&c != re_is_set_member(&c, &c + 1, static_cast<re_set_long<mask_type>*>(state), *m_pdata, m_icase))
+ if(&c != re_is_set_member(&c, &c + 1, static_cast<re_set_long<mask_type>*>(state), *m_pdata, l_icase))
                      l_map[i] |= mask;
                }
             }

Modified: branches/release/boost/regex/v4/regex_format.hpp
==============================================================================
--- branches/release/boost/regex/v4/regex_format.hpp (original)
+++ branches/release/boost/regex/v4/regex_format.hpp 2011-10-16 08:19:37 EDT (Sun, 16 Oct 2011)
@@ -842,7 +842,15 @@
 
 BOOST_MPL_HAS_XXX_TRAIT_DEF(const_iterator)
 
-struct any_type { any_type(...); };
+struct any_type
+{
+ template <class T>
+ any_type(const T&);
+ template <class T, class U>
+ any_type(const T&, const U&);
+ template <class T, class U, class V>
+ any_type(const T&, const U&, const V&);
+};
 typedef char no_type;
 typedef char (&unary_type)[2];
 typedef char (&binary_type)[3];

Modified: branches/release/libs/regex/src/c_regex_traits.cpp
==============================================================================
--- branches/release/libs/regex/src/c_regex_traits.cpp (original)
+++ branches/release/libs/regex/src/c_regex_traits.cpp 2011-10-16 08:19:37 EDT (Sun, 16 Oct 2011)
@@ -21,6 +21,7 @@
 
 #include <boost/config.hpp>
 #include <boost/detail/workaround.hpp>
+#include "internals.hpp"
 
 #if !BOOST_WORKAROUND(__BORLANDC__, < 0x560)
 
@@ -107,26 +108,6 @@
    return result;
 }
 
-enum
-{
- char_class_space=1<<0,
- char_class_print=1<<1,
- char_class_cntrl=1<<2,
- char_class_upper=1<<3,
- char_class_lower=1<<4,
- char_class_alpha=1<<5,
- char_class_digit=1<<6,
- char_class_punct=1<<7,
- char_class_xdigit=1<<8,
- char_class_alnum=char_class_alpha|char_class_digit,
- char_class_graph=char_class_alnum|char_class_punct,
- char_class_blank=1<<9,
- char_class_word=1<<10,
- char_class_unicode=1<<11,
- char_class_horizontal=1<<12,
- char_class_vertical=1<<13
-};
-
 c_regex_traits<char>::char_class_type BOOST_REGEX_CALL c_regex_traits<char>::lookup_classname(const char* p1, const char* p2)
 {
    static const char_class_type masks[] =

Modified: branches/release/libs/regex/src/cregex.cpp
==============================================================================
--- branches/release/libs/regex/src/cregex.cpp (original)
+++ branches/release/libs/regex/src/cregex.cpp 2011-10-16 08:19:37 EDT (Sun, 16 Oct 2011)
@@ -361,11 +361,24 @@
 
       while(dstart != dend)
       {
+ // Verify that sprintf will not overflow:
+ if(std::strlen(dstart.path()) + std::strlen(directory_iterator::separator()) + std::strlen(ptr) >= MAX_PATH)
+ {
+ // Oops overflow, skip this item:
+ ++dstart;
+ continue;
+ }
 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400) && !defined(_WIN32_WCE) && !defined(UNDER_CE)
- (::sprintf_s)(buf, sizeof(buf), "%s%s%s", dstart.path(), directory_iterator::separator(), ptr);
+ int r = (::sprintf_s)(buf, sizeof(buf), "%s%s%s", dstart.path(), directory_iterator::separator(), ptr);
 #else
- (std::sprintf)(buf, "%s%s%s", dstart.path(), directory_iterator::separator(), ptr);
+ int r = (std::sprintf)(buf, "%s%s%s", dstart.path(), directory_iterator::separator(), ptr);
 #endif
+ if(r < 0)
+ {
+ // sprintf failed, skip this item:
+ ++dstart;
+ continue;
+ }
          BuildFileList(pl, buf, recurse);
          ++dstart;
       }

Modified: branches/release/libs/regex/src/fileiter.cpp
==============================================================================
--- branches/release/libs/regex/src/fileiter.cpp (original)
+++ branches/release/libs/regex/src/fileiter.cpp 2011-10-16 08:19:37 EDT (Sun, 16 Oct 2011)
@@ -847,10 +847,16 @@
 unsigned _fi_attributes(const char* root, const char* name)
 {
    char buf[MAX_PATH];
+ // verify that we can not overflow:
+ if(std::strlen(root) + std::strlen(_fi_sep) + std::strlen(name) >= MAX_PATH)
+ return 0;
+ int r;
    if( ( (root[0] == *_fi_sep) || (root[0] == *_fi_sep_alt) ) && (root[1] == '\0') )
- (std::sprintf)(buf, "%s%s", root, name);
+ r = (std::sprintf)(buf, "%s%s", root, name);
    else
- (std::sprintf)(buf, "%s%s%s", root, _fi_sep, name);
+ r = (std::sprintf)(buf, "%s%s%s", root, _fi_sep, name);
+ if(r < 0)
+ return 0; // sprintf failed
    DIR* d = opendir(buf);
    if(d)
    {

Modified: branches/release/libs/regex/src/posix_api.cpp
==============================================================================
--- branches/release/libs/regex/src/posix_api.cpp (original)
+++ branches/release/libs/regex/src/posix_api.cpp 2011-10-16 08:19:37 EDT (Sun, 16 Oct 2011)
@@ -167,11 +167,17 @@
       {
          if(std::strcmp(e->re_endp, names[i]) == 0)
          {
+ //
+ // We're converting an integer i to a string, and since i <= REG_E_UNKNOWN
+ // a five character string is *always* large enough:
+ //
 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400) && !defined(_WIN32_WCE) && !defined(UNDER_CE)
- (::sprintf_s)(localbuf, 5, "%d", i);
+ int r = (::sprintf_s)(localbuf, 5, "%d", i);
 #else
- (std::sprintf)(localbuf, "%d", i);
+ int r = (std::sprintf)(localbuf, "%d", i);
 #endif
+ if(r < 0)
+ return 0; // sprintf failed
             if(std::strlen(localbuf) < buf_size)
                re_detail::strcpy_s(buf, buf_size, localbuf);
             return std::strlen(localbuf) + 1;

Modified: branches/release/libs/regex/src/wc_regex_traits.cpp
==============================================================================
--- branches/release/libs/regex/src/wc_regex_traits.cpp (original)
+++ branches/release/libs/regex/src/wc_regex_traits.cpp 2011-10-16 08:19:37 EDT (Sun, 16 Oct 2011)
@@ -22,6 +22,7 @@
 #include <boost/detail/workaround.hpp>
 #include <memory>
 #include <string>
+#include "internals.hpp"
 
 #if defined(_DLL_CPPLIB) && !defined(_M_CEE_PURE) && defined(_NATIVE_WCHAR_T_DEFINED) \
    && !(defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION) || defined(__STD_RWCOMPILER_H__) || defined(_RWSTD_VER))\
@@ -147,26 +148,6 @@
    return result;
 }
 
-enum
-{
- char_class_space=1<<0,
- char_class_print=1<<1,
- char_class_cntrl=1<<2,
- char_class_upper=1<<3,
- char_class_lower=1<<4,
- char_class_alpha=1<<5,
- char_class_digit=1<<6,
- char_class_punct=1<<7,
- char_class_xdigit=1<<8,
- char_class_alnum=char_class_alpha|char_class_digit,
- char_class_graph=char_class_alnum|char_class_punct,
- char_class_blank=1<<9,
- char_class_word=1<<10,
- char_class_unicode=1<<11,
- char_class_horizontal=1<<12,
- char_class_vertical=1<<13
-};
-
 c_regex_traits<wchar_t>::char_class_type BOOST_REGEX_CALL c_regex_traits<wchar_t>::lookup_classname(const wchar_t* p1, const wchar_t* p2)
 {
    static const char_class_type masks[] =

Modified: branches/release/libs/regex/src/wide_posix_api.cpp
==============================================================================
--- branches/release/libs/regex/src/wide_posix_api.cpp (original)
+++ branches/release/libs/regex/src/wide_posix_api.cpp 2011-10-16 08:19:37 EDT (Sun, 16 Oct 2011)
@@ -74,7 +74,7 @@
 };
 }
 
-typedef boost::basic_regex<wchar_t, c_regex_traits<wchar_t> > c_regex_type;
+typedef boost::basic_regex<wchar_t, c_regex_traits<wchar_t> > wc_regex_type;
 
 BOOST_REGEX_DECL int BOOST_REGEX_CCALL regcompW(regex_tW* expression, const wchar_t* ptr, int f)
 {
@@ -84,7 +84,7 @@
 #ifndef BOOST_NO_EXCEPTIONS
       try{
 #endif
- expression->guts = new c_regex_type();
+ expression->guts = new wc_regex_type();
 #ifndef BOOST_NO_EXCEPTIONS
       } catch(...)
       {
@@ -134,9 +134,9 @@
    try{
 #endif
       expression->re_magic = wmagic_value;
- static_cast<c_regex_type*>(expression->guts)->set_expression(ptr, p2, flags);
- expression->re_nsub = static_cast<c_regex_type*>(expression->guts)->mark_count() - 1;
- result = static_cast<c_regex_type*>(expression->guts)->error_code();
+ static_cast<wc_regex_type*>(expression->guts)->set_expression(ptr, p2, flags);
+ expression->re_nsub = static_cast<wc_regex_type*>(expression->guts)->mark_count() - 1;
+ result = static_cast<wc_regex_type*>(expression->guts)->error_code();
 #ifndef BOOST_NO_EXCEPTIONS
    }
    catch(const boost::regex_error& be)
@@ -215,7 +215,7 @@
    {
       std::string p;
       if((e) && (e->re_magic == wmagic_value))
- p = static_cast<c_regex_type*>(e->guts)->get_traits().error_string(static_cast< ::boost::regex_constants::error_type>(code));
+ p = static_cast<wc_regex_type*>(e->guts)->get_traits().error_string(static_cast< ::boost::regex_constants::error_type>(code));
       else
       {
          p = re_detail::get_default_error_string(static_cast< ::boost::regex_constants::error_type>(code));
@@ -264,7 +264,7 @@
 #endif
    if(expression->re_magic == wmagic_value)
    {
- result = regex_search(start, end, m, *static_cast<c_regex_type*>(expression->guts), flags);
+ result = regex_search(start, end, m, *static_cast<wc_regex_type*>(expression->guts), flags);
    }
    else
       return result;
@@ -301,7 +301,7 @@
 {
    if(expression->re_magic == wmagic_value)
    {
- delete static_cast<c_regex_type*>(expression->guts);
+ delete static_cast<wc_regex_type*>(expression->guts);
    }
    expression->re_magic = 0;
 }

Modified: branches/release/libs/regex/test/Jamfile.v2
==============================================================================
--- branches/release/libs/regex/test/Jamfile.v2 (original)
+++ branches/release/libs/regex/test/Jamfile.v2 2011-10-16 08:19:37 EDT (Sun, 16 Oct 2011)
@@ -189,6 +189,8 @@
 
 ;
 
+compile test_consolidated.cpp ;
+
 build-project ../example ;
 
 

Modified: branches/release/libs/regex/test/regress/test_perl_ex.cpp
==============================================================================
--- branches/release/libs/regex/test/regress/test_perl_ex.cpp (original)
+++ branches/release/libs/regex/test/regress/test_perl_ex.cpp 2011-10-16 08:19:37 EDT (Sun, 16 Oct 2011)
@@ -216,6 +216,10 @@
    TEST_REGEX_SEARCH("(a(?i)b)c", perl, "ABc", match_default, make_array(-2, -2));
    TEST_REGEX_SEARCH("(a(?i)b)c", perl, "ABC", match_default, make_array(-2, -2));
    TEST_REGEX_SEARCH("(a(?i)b)c", perl, "AbC", match_default, make_array(-2, -2));
+ TEST_REGEX_SEARCH("(?i)[dh]og", perl, "hog", match_default, make_array(0, 3, -2, -2));
+ TEST_REGEX_SEARCH("(?i)[dh]og", perl, "dog", match_default, make_array(0, 3, -2, -2));
+ TEST_REGEX_SEARCH("(?i)[dh]og", perl, "Hog", match_default, make_array(0, 3, -2, -2));
+ TEST_REGEX_SEARCH("(?i)[dh]og", perl, "Dog", match_default, make_array(0, 3, -2, -2));
    
    TEST_REGEX_SEARCH("(a(?i)B)c", perl, "abc", match_default, make_array(0, 3, 0, 2, -2, -2));
    TEST_REGEX_SEARCH("(a(?i)B)c", perl, "aBc", match_default, make_array(0, 3, 0, 2, -2, -2));

Modified: branches/release/libs/regex/test/unicode/unicode_iterator_test.cpp
==============================================================================
--- branches/release/libs/regex/test/unicode/unicode_iterator_test.cpp (original)
+++ branches/release/libs/regex/test/unicode/unicode_iterator_test.cpp 2011-10-16 08:19:37 EDT (Sun, 16 Oct 2011)
@@ -30,7 +30,7 @@
 template <class I>
 typename I::value_type iterate_over(I a, I b)
 {
- typedef I::value_type value_type;
+ typedef typename I::value_type value_type;
    value_type v = 0;
    while(a != b)
    {


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk