| 1 |
// { dg-do run { target c++11 } } |
| 2 |
|
| 3 |
#include <regex> |
| 4 |
#include <string> |
| 5 |
#include <climits> |
| 6 |
#include <testsuite_hooks.h> |
| 7 |
|
| 8 |
// PR libstdc++/106607 - Regex integer overflow on large backreference value |
| 9 |
|
| 10 |
int main() |
| 11 |
{ |
| 12 |
std::regex r("(.)\\1"); // OK |
| 13 |
|
| 14 |
try |
| 15 |
{ |
| 16 |
long long n = (unsigned)-1 + 2LL; // 4294967297 for 32-bit int |
| 17 |
VERIFY( (int)n == 1 ); // 4294967297 % 2^32 == 1 |
| 18 |
std::regex r("(.)\\" + std::to_string(n)); // Invalid back reference. |
| 19 |
VERIFY(false); |
| 20 |
} |
| 21 |
catch (const std::regex_error& e) |
| 22 |
{ |
| 23 |
VERIFY( e.code() == std::regex_constants::error_backref ); |
| 24 |
} |
| 25 |
} |