[libcxx] r186335 - Bill Fisher: This patch fixes an ill-formed comparison when parsing control escapes, e.g. "\cA\ca". The code will now throw an error_escape exception for invalid control sequences like "\c:" or "\c".
Howard Hinnant
hhinnant at apple.com
Mon Jul 15 11:21:11 PDT 2013
Author: hhinnant
Date: Mon Jul 15 13:21:11 2013
New Revision: 186335
URL: http://llvm.org/viewvc/llvm-project?rev=186335&view=rev
Log:
Bill Fisher: This patch fixes an ill-formed comparison when parsing control escapes, e.g. "\cA\ca". The code will now throw an error_escape exception for invalid control sequences like "\c:" or "\c".
I've added the test cases to bad_escape.pass.cpp.
Modified:
libcxx/trunk/include/regex
libcxx/trunk/test/re/re.regex/re.regex.construct/bad_escape.pass.cpp
Modified: libcxx/trunk/include/regex
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/regex?rev=186335&r1=186334&r2=186335&view=diff
==============================================================================
--- libcxx/trunk/include/regex (original)
+++ libcxx/trunk/include/regex Mon Jul 15 13:21:11 2013
@@ -4418,7 +4418,8 @@ basic_regex<_CharT, _Traits>::__parse_ch
case 'c':
if ((__t = _VSTD::next(__first)) != __last)
{
- if ('A' <= *__t <= 'Z' || 'a' <= *__t <= 'z')
+ if (('A' <= *__t && *__t <= 'Z') ||
+ ('a' <= *__t && *__t <= 'z'))
{
if (__str)
*__str = _CharT(*__t % 32);
@@ -4426,7 +4427,15 @@ basic_regex<_CharT, _Traits>::__parse_ch
__push_char(_CharT(*__t % 32));
__first = ++__t;
}
+#ifndef _LIBCPP_NO_EXCEPTIONS
+ else
+ throw regex_error(regex_constants::error_escape);
+#endif // _LIBCPP_NO_EXCEPTIONS
}
+#ifndef _LIBCPP_NO_EXCEPTIONS
+ else
+ throw regex_error(regex_constants::error_escape);
+#endif // _LIBCPP_NO_EXCEPTIONS
break;
case 'u':
++__first;
Modified: libcxx/trunk/test/re/re.regex/re.regex.construct/bad_escape.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/re/re.regex/re.regex.construct/bad_escape.pass.cpp?rev=186335&r1=186334&r2=186335&view=diff
==============================================================================
--- libcxx/trunk/test/re/re.regex/re.regex.construct/bad_escape.pass.cpp (original)
+++ libcxx/trunk/test/re/re.regex/re.regex.construct/bad_escape.pass.cpp Mon Jul 15 13:21:11 2013
@@ -17,21 +17,29 @@
#include <regex>
#include <cassert>
-int main()
+static bool error_escape_thrown(const char *pat)
{
- // Correct: Exception thrown for invalid escape char in a character class
+ bool result = false;
try {
- std::regex char_class_escape("[\\a]");
- assert(false);
+ std::regex re(pat);
} catch (std::regex_error &ex) {
- assert(ex.code() == std::regex_constants::error_escape);
+ result = (ex.code() == std::regex_constants::error_escape);
}
+ return result;
+}
+
+int main()
+{
+ assert(error_escape_thrown("[\\a]"));
+ assert(error_escape_thrown("\\a"));
+
+ assert(error_escape_thrown("[\\e]"));
+ assert(error_escape_thrown("\\e"));
+
+ assert(error_escape_thrown("[\\c:]"));
+ assert(error_escape_thrown("\\c:"));
+ assert(error_escape_thrown("\\c"));
+ assert(!error_escape_thrown("[\\cA]"));
+ assert(!error_escape_thrown("\\cA"));
- // Failure: No exception thrown for invalid escape char in this case.
- try {
- std::regex escape("\\a");
- assert(false);
- } catch (std::regex_error &ex) {
- assert(ex.code() == std::regex_constants::error_escape);
- }
}
More information about the cfe-commits
mailing list