mirror of
https://github.com/boostorg/regex.git
synced 2025-07-29 12:07:28 +02:00
1) Disabled recursive implementation for VC8: stack overflows can't be reliably detected unless the whole program is compiled with asynchronous exceptions.
2) Changed std::copy calls on VC8 to avoid "dangerous code" warnings. 3) Moved backreference and octal escape code into line with POSIX-extended requirements. 4) Changed match_results leftmost-longest rules to stop unnecessary std::distance computations (an optimisation for non-random access iterators). 5) Changed C lib calls to use "safe" versions of string API's where available. 6) Added many new POSIX-extended leftmost-longest tests, to verify the above. [SVN r27880]
This commit is contained in:
@ -33,12 +33,6 @@ typedef boost::match_flag_type match_flag_type;
|
||||
#endif
|
||||
#include <cstdio>
|
||||
|
||||
#if defined(BOOST_NO_STDC_NAMESPACE)
|
||||
namespace std{
|
||||
using ::sprintf; using ::strcpy; using ::strcat;
|
||||
}
|
||||
#endif
|
||||
|
||||
namespace boost{
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
@ -342,17 +336,17 @@ void BuildFileList(std::list<std::string>* pl, const char* files, bool recurse)
|
||||
{
|
||||
// go through sub directories:
|
||||
char buf[MAX_PATH];
|
||||
std::strcpy(buf, start.root());
|
||||
re_detail::overflow_error_if_not_zero(re_detail::strcpy_s(buf, MAX_PATH, start.root()));
|
||||
if(*buf == 0)
|
||||
{
|
||||
std::strcpy(buf, ".");
|
||||
std::strcat(buf, directory_iterator::separator());
|
||||
std::strcat(buf, "*");
|
||||
re_detail::overflow_error_if_not_zero(re_detail::strcpy_s(buf, MAX_PATH, "."));
|
||||
re_detail::overflow_error_if_not_zero(re_detail::strcat_s(buf, MAX_PATH, directory_iterator::separator()));
|
||||
re_detail::overflow_error_if_not_zero(re_detail::strcat_s(buf, MAX_PATH, "*"));
|
||||
}
|
||||
else
|
||||
{
|
||||
std::strcat(buf, directory_iterator::separator());
|
||||
std::strcat(buf, "*");
|
||||
re_detail::overflow_error_if_not_zero(re_detail::strcat_s(buf, MAX_PATH, directory_iterator::separator()));
|
||||
re_detail::overflow_error_if_not_zero(re_detail::strcat_s(buf, MAX_PATH, "*"));
|
||||
}
|
||||
directory_iterator dstart(buf);
|
||||
directory_iterator dend;
|
||||
@ -365,7 +359,11 @@ void BuildFileList(std::list<std::string>* pl, const char* files, bool recurse)
|
||||
|
||||
while(dstart != dend)
|
||||
{
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
|
||||
(::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);
|
||||
#endif
|
||||
BuildFileList(pl, buf, recurse);
|
||||
++dstart;
|
||||
}
|
||||
|
@ -23,11 +23,8 @@
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <boost/throw_exception.hpp>
|
||||
#ifdef BOOST_REGEX_V3
|
||||
#include <boost/regex/v3/fileiter.hpp>
|
||||
#else
|
||||
#include <boost/regex/v4/fileiter.hpp>
|
||||
#endif
|
||||
#include <boost/regex/v4/regex_workaround.hpp>
|
||||
#include <boost/regex/pattern_except.hpp>
|
||||
|
||||
#include <cstdio>
|
||||
@ -395,34 +392,24 @@ file_iterator::file_iterator(const char* wild)
|
||||
BOOST_REGEX_NOEH_ASSERT(_root)
|
||||
_path = new char[MAX_PATH];
|
||||
BOOST_REGEX_NOEH_ASSERT(_path)
|
||||
std::strcpy(_root, wild);
|
||||
re_detail::overflow_error_if_not_zero(re_detail::strcpy_s(_root, MAX_PATH, wild));
|
||||
ptr = _root;
|
||||
while(*ptr)++ptr;
|
||||
while((ptr > _root) && (*ptr != *_fi_sep) && (*ptr != *_fi_sep_alt))--ptr;
|
||||
#if 0
|
||||
*ptr = 0;
|
||||
std::strcpy(_path, _root);
|
||||
if(*_path == 0)
|
||||
std::strcpy(_path, ".");
|
||||
std::strcat(_path, _fi_sep);
|
||||
ptr = _path + std::strlen(_path);
|
||||
#else
|
||||
if((ptr == _root) && ( (*ptr== *_fi_sep) || (*ptr==*_fi_sep_alt) ) )
|
||||
{
|
||||
_root[1]='\0';
|
||||
std::strcpy(_path, _root);
|
||||
ptr = _path + std::strlen(_path);
|
||||
re_detail::overflow_error_if_not_zero(re_detail::strcpy_s(_path, MAX_PATH, _root));
|
||||
}
|
||||
else
|
||||
{
|
||||
*ptr = 0;
|
||||
std::strcpy(_path, _root);
|
||||
re_detail::overflow_error_if_not_zero(re_detail::strcpy_s(_path, MAX_PATH, _root));
|
||||
if(*_path == 0)
|
||||
std::strcpy(_path, ".");
|
||||
std::strcat(_path, _fi_sep);
|
||||
ptr = _path + std::strlen(_path);
|
||||
re_detail::overflow_error_if_not_zero(re_detail::strcpy_s(_path, MAX_PATH, "."));
|
||||
re_detail::overflow_error_if_not_zero(re_detail::strcat_s(_path, MAX_PATH, _fi_sep));
|
||||
}
|
||||
#endif
|
||||
ptr = _path + std::strlen(_path);
|
||||
|
||||
ref = new file_iterator_ref();
|
||||
BOOST_REGEX_NOEH_ASSERT(ref)
|
||||
@ -436,7 +423,7 @@ file_iterator::file_iterator(const char* wild)
|
||||
}
|
||||
else
|
||||
{
|
||||
std::strcpy(ptr, ref->_data.cFileName);
|
||||
re_detail::overflow_error_if_not_zero(re_detail::strcpy_s(ptr, (MAX_PATH - (ptr - _path)), ref->_data.cFileName));
|
||||
if(ref->_data.dwFileAttributes & _fi_dir)
|
||||
next();
|
||||
}
|
||||
@ -463,8 +450,8 @@ file_iterator::file_iterator(const file_iterator& other)
|
||||
BOOST_REGEX_NOEH_ASSERT(_root)
|
||||
_path = new char[MAX_PATH];
|
||||
BOOST_REGEX_NOEH_ASSERT(_path)
|
||||
std::strcpy(_root, other._root);
|
||||
std::strcpy(_path, other._path);
|
||||
re_detail::overflow_error_if_not_zero(re_detail::strcpy_s(_root, MAX_PATH, other._root));
|
||||
re_detail::overflow_error_if_not_zero(re_detail::strcpy_s(_path, MAX_PATH, other._path));
|
||||
ptr = _path + (other.ptr - other._path);
|
||||
ref = other.ref;
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
@ -481,8 +468,8 @@ file_iterator::file_iterator(const file_iterator& other)
|
||||
|
||||
file_iterator& file_iterator::operator=(const file_iterator& other)
|
||||
{
|
||||
std::strcpy(_root, other._root);
|
||||
std::strcpy(_path, other._path);
|
||||
re_detail::overflow_error_if_not_zero(re_detail::strcpy_s(_root, MAX_PATH, other._root));
|
||||
re_detail::overflow_error_if_not_zero(re_detail::strcpy_s(_path, MAX_PATH, other._path));
|
||||
ptr = _path + (other.ptr - other._path);
|
||||
if(--(ref->count) == 0)
|
||||
{
|
||||
@ -536,7 +523,7 @@ void file_iterator::next()
|
||||
ptr = _path;
|
||||
}
|
||||
else
|
||||
std::strcpy(ptr, ref->_data.cFileName);
|
||||
re_detail::overflow_error_if_not_zero(re_detail::strcpy_s(ptr, MAX_PATH - (ptr - _path), ref->_data.cFileName));
|
||||
}
|
||||
}
|
||||
|
||||
@ -583,34 +570,26 @@ directory_iterator::directory_iterator(const char* wild)
|
||||
BOOST_REGEX_NOEH_ASSERT(_root)
|
||||
_path = new char[MAX_PATH];
|
||||
BOOST_REGEX_NOEH_ASSERT(_path)
|
||||
std::strcpy(_root, wild);
|
||||
re_detail::overflow_error_if_not_zero(re_detail::strcpy_s(_root, MAX_PATH, wild));
|
||||
ptr = _root;
|
||||
while(*ptr)++ptr;
|
||||
while((ptr > _root) && (*ptr != *_fi_sep) && (*ptr != *_fi_sep_alt))--ptr;
|
||||
#if 0
|
||||
*ptr = 0;
|
||||
std::strcpy(_path, _root);
|
||||
if(*_path == 0)
|
||||
std::strcpy(_path, ".");
|
||||
std::strcat(_path, _fi_sep);
|
||||
ptr = _path + std::strlen(_path);
|
||||
#else
|
||||
|
||||
if((ptr == _root) && ( (*ptr== *_fi_sep) || (*ptr==*_fi_sep_alt) ) )
|
||||
{
|
||||
_root[1]='\0';
|
||||
std::strcpy(_path, _root);
|
||||
ptr = _path + std::strlen(_path);
|
||||
re_detail::overflow_error_if_not_zero(re_detail::strcpy_s(_path, MAX_PATH, _root));
|
||||
}
|
||||
else
|
||||
{
|
||||
*ptr = 0;
|
||||
std::strcpy(_path, _root);
|
||||
re_detail::overflow_error_if_not_zero(re_detail::strcpy_s(_path, MAX_PATH, _root));
|
||||
if(*_path == 0)
|
||||
std::strcpy(_path, ".");
|
||||
std::strcat(_path, _fi_sep);
|
||||
ptr = _path + std::strlen(_path);
|
||||
re_detail::overflow_error_if_not_zero(re_detail::strcpy_s(_path, MAX_PATH, "."));
|
||||
re_detail::overflow_error_if_not_zero(re_detail::strcat_s(_path, MAX_PATH, _fi_sep));
|
||||
}
|
||||
#endif
|
||||
ptr = _path + std::strlen(_path);
|
||||
|
||||
ref = new file_iterator_ref();
|
||||
BOOST_REGEX_NOEH_ASSERT(ref)
|
||||
ref->count = 1;
|
||||
@ -622,7 +601,7 @@ directory_iterator::directory_iterator(const char* wild)
|
||||
}
|
||||
else
|
||||
{
|
||||
std::strcpy(ptr, ref->_data.cFileName);
|
||||
re_detail::overflow_error_if_not_zero(re_detail::strcpy_s(ptr, MAX_PATH - (ptr - _path), ref->_data.cFileName));
|
||||
if(((ref->_data.dwFileAttributes & _fi_dir) == 0) || (std::strcmp(ref->_data.cFileName, ".") == 0) || (std::strcmp(ref->_data.cFileName, "..") == 0))
|
||||
next();
|
||||
}
|
||||
@ -661,8 +640,8 @@ directory_iterator::directory_iterator(const directory_iterator& other)
|
||||
BOOST_REGEX_NOEH_ASSERT(_root)
|
||||
_path = new char[MAX_PATH];
|
||||
BOOST_REGEX_NOEH_ASSERT(_path)
|
||||
std::strcpy(_root, other._root);
|
||||
std::strcpy(_path, other._path);
|
||||
re_detail::overflow_error_if_not_zero(re_detail::strcpy_s(_root, MAX_PATH, other._root));
|
||||
re_detail::overflow_error_if_not_zero(re_detail::strcpy_s(_path, MAX_PATH, other._path));
|
||||
ptr = _path + (other.ptr - other._path);
|
||||
ref = other.ref;
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
@ -679,8 +658,8 @@ directory_iterator::directory_iterator(const directory_iterator& other)
|
||||
|
||||
directory_iterator& directory_iterator::operator=(const directory_iterator& other)
|
||||
{
|
||||
std::strcpy(_root, other._root);
|
||||
std::strcpy(_path, other._path);
|
||||
re_detail::overflow_error_if_not_zero(re_detail::strcpy_s(_root, MAX_PATH, other._root));
|
||||
re_detail::overflow_error_if_not_zero(re_detail::strcpy_s(_path, MAX_PATH, other._path));
|
||||
ptr = _path + (other.ptr - other._path);
|
||||
if(--(ref->count) == 0)
|
||||
{
|
||||
@ -723,7 +702,7 @@ void directory_iterator::next()
|
||||
ptr = _path;
|
||||
}
|
||||
else
|
||||
std::strcpy(ptr, ref->_data.cFileName);
|
||||
re_detail::overflow_error_if_not_zero(re_detail::strcpy_s(ptr, MAX_PATH - (ptr - _path), ref->_data.cFileName));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -131,7 +131,7 @@ BOOST_REGEX_DECL regsize_t BOOST_REGEX_CCALL regerrorA(int code, const regex_tA*
|
||||
{
|
||||
result = std::strlen(names[code]) + 1;
|
||||
if(buf_size >= result)
|
||||
std::strcpy(buf, names[code]);
|
||||
re_detail::strcpy_s(buf, buf_size, names[code]);
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
@ -145,15 +145,23 @@ BOOST_REGEX_DECL regsize_t BOOST_REGEX_CCALL regerrorA(int code, const regex_tA*
|
||||
{
|
||||
if(std::strcmp(e->re_endp, names[i]) == 0)
|
||||
{
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
|
||||
(::sprintf_s)(localbuf, 5, "%d", i);
|
||||
#else
|
||||
(std::sprintf)(localbuf, "%d", i);
|
||||
#endif
|
||||
if(std::strlen(localbuf) < buf_size)
|
||||
std::strcpy(buf, localbuf);
|
||||
re_detail::strcpy_s(buf, buf_size, localbuf);
|
||||
return std::strlen(localbuf) + 1;
|
||||
}
|
||||
}
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
|
||||
(::sprintf_s)(localbuf, 5, "%d", 0);
|
||||
#else
|
||||
(std::sprintf)(localbuf, "%d", 0);
|
||||
#endif
|
||||
if(std::strlen(localbuf) < buf_size)
|
||||
std::strcpy(buf, localbuf);
|
||||
re_detail::strcpy_s(buf, buf_size, localbuf);
|
||||
return std::strlen(localbuf) + 1;
|
||||
}
|
||||
if(code <= (int)REG_E_UNKNOWN)
|
||||
@ -168,7 +176,7 @@ BOOST_REGEX_DECL regsize_t BOOST_REGEX_CCALL regerrorA(int code, const regex_tA*
|
||||
std::size_t len = p.size();
|
||||
if(len < buf_size)
|
||||
{
|
||||
std::strcpy(buf, p.c_str());
|
||||
re_detail::strcpy_s(buf, buf_size, p.c_str());
|
||||
}
|
||||
return len + 1;
|
||||
}
|
||||
|
@ -231,7 +231,7 @@ BOOST_REGEX_DECL std::string BOOST_REGEX_CALL w32_transform(lcid_type id, const
|
||||
id, // locale identifier
|
||||
LCMAP_SORTKEY, // mapping transformation type
|
||||
p1, // source string
|
||||
p2 - p1, // number of characters in source string
|
||||
static_cast<int>(p2 - p1), // number of characters in source string
|
||||
0, // destination buffer
|
||||
0 // size of destination buffer
|
||||
);
|
||||
@ -242,7 +242,7 @@ BOOST_REGEX_DECL std::string BOOST_REGEX_CALL w32_transform(lcid_type id, const
|
||||
id, // locale identifier
|
||||
LCMAP_SORTKEY, // mapping transformation type
|
||||
p1, // source string
|
||||
p2 - p1, // number of characters in source string
|
||||
static_cast<int>(p2 - p1), // number of characters in source string
|
||||
&*result.begin(), // destination buffer
|
||||
bytes // size of destination buffer
|
||||
);
|
||||
@ -262,7 +262,7 @@ BOOST_REGEX_DECL std::wstring BOOST_REGEX_CALL w32_transform(lcid_type id, const
|
||||
id, // locale identifier
|
||||
LCMAP_SORTKEY, // mapping transformation type
|
||||
p1, // source string
|
||||
p2 - p1, // number of characters in source string
|
||||
static_cast<int>(p2 - p1), // number of characters in source string
|
||||
0, // destination buffer
|
||||
0 // size of destination buffer
|
||||
);
|
||||
@ -273,7 +273,7 @@ BOOST_REGEX_DECL std::wstring BOOST_REGEX_CALL w32_transform(lcid_type id, const
|
||||
id, // locale identifier
|
||||
LCMAP_SORTKEY, // mapping transformation type
|
||||
p1, // source string
|
||||
p2 - p1, // number of characters in source string
|
||||
static_cast<int>(p2 - p1), // number of characters in source string
|
||||
reinterpret_cast<wchar_t*>(&*result.begin()), // destination buffer *of bytes*
|
||||
bytes // size of destination buffer
|
||||
);
|
||||
@ -295,7 +295,7 @@ BOOST_REGEX_DECL std::basic_string<unsigned short> BOOST_REGEX_CALL w32_transfor
|
||||
id, // locale identifier
|
||||
LCMAP_SORTKEY, // mapping transformation type
|
||||
(LPCWSTR)p1, // source string
|
||||
p2 - p1, // number of characters in source string
|
||||
static_cast<int>(p2 - p1), // number of characters in source string
|
||||
0, // destination buffer
|
||||
0 // size of destination buffer
|
||||
);
|
||||
@ -306,7 +306,7 @@ BOOST_REGEX_DECL std::basic_string<unsigned short> BOOST_REGEX_CALL w32_transfor
|
||||
id, // locale identifier
|
||||
LCMAP_SORTKEY, // mapping transformation type
|
||||
(LPCWSTR)p1, // source string
|
||||
p2 - p1, // number of characters in source string
|
||||
static_cast<int>(p2 - p1), // number of characters in source string
|
||||
reinterpret_cast<wchar_t*>(&*result.begin()), // destination buffer *of bytes*
|
||||
bytes // size of destination buffer
|
||||
);
|
||||
|
@ -139,7 +139,11 @@ BOOST_REGEX_DECL regsize_t BOOST_REGEX_CCALL regerrorW(int code, const regex_tW*
|
||||
{
|
||||
result = std::wcslen(wnames[code]) + 1;
|
||||
if(buf_size >= result)
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
|
||||
::wcscpy_s(buf, buf_size, wnames[code]);
|
||||
#else
|
||||
std::wcscpy(buf, wnames[code]);
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
@ -156,13 +160,21 @@ BOOST_REGEX_DECL regsize_t BOOST_REGEX_CCALL regerrorW(int code, const regex_tW*
|
||||
{
|
||||
(std::swprintf)(localbuf, 5, L"%d", i);
|
||||
if(std::wcslen(localbuf) < buf_size)
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
|
||||
::wcscpy_s(buf, buf_size, localbuf);
|
||||
#else
|
||||
std::wcscpy(buf, localbuf);
|
||||
#endif
|
||||
return std::wcslen(localbuf) + 1;
|
||||
}
|
||||
}
|
||||
(std::swprintf)(localbuf, 5, L"%d", 0);
|
||||
if(std::wcslen(localbuf) < buf_size)
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
|
||||
::wcscpy_s(buf, buf_size, localbuf);
|
||||
#else
|
||||
std::wcscpy(buf, localbuf);
|
||||
#endif
|
||||
return std::wcslen(localbuf) + 1;
|
||||
}
|
||||
#endif
|
||||
@ -178,7 +190,7 @@ BOOST_REGEX_DECL regsize_t BOOST_REGEX_CCALL regerrorW(int code, const regex_tW*
|
||||
std::size_t len = p.size();
|
||||
if(len < buf_size)
|
||||
{
|
||||
std::copy(p.c_str(), p.c_str() + p.size() + 1, buf);
|
||||
re_detail::copy(p.c_str(), p.c_str() + p.size() + 1, buf);
|
||||
}
|
||||
return len + 1;
|
||||
}
|
||||
|
Reference in New Issue
Block a user