| 1054 | } |
| 1055 | |
| 1056 | void Compiler::Setup(Regexp::ParseFlags flags, int64_t max_mem, |
| 1057 | RE2::Anchor anchor) { |
| 1058 | if (flags & Regexp::Latin1) |
| 1059 | encoding_ = kEncodingLatin1; |
| 1060 | max_mem_ = max_mem; |
| 1061 | if (max_mem <= 0) { |
| 1062 | max_ninst_ = 100000; // more than enough |
| 1063 | } else if (static_cast<size_t>(max_mem) <= sizeof(Prog)) { |
| 1064 | // No room for anything. |
| 1065 | max_ninst_ = 0; |
| 1066 | } else { |
| 1067 | int64_t m = (max_mem - sizeof(Prog)) / sizeof(Prog::Inst); |
| 1068 | // Limit instruction count so that inst->id() fits nicely in an int. |
| 1069 | // SparseArray also assumes that the indices (inst->id()) are ints. |
| 1070 | // The call to WalkExponential uses 2*max_ninst_ below, |
| 1071 | // and other places in the code use 2 or 3 * prog->size(). |
| 1072 | // Limiting to 2^24 should avoid overflow in those places. |
| 1073 | // (The point of allowing more than 32 bits of memory is to |
| 1074 | // have plenty of room for the DFA states, not to use it up |
| 1075 | // on the program.) |
| 1076 | if (m >= 1<<24) |
| 1077 | m = 1<<24; |
| 1078 | // Inst imposes its own limit (currently bigger than 2^24 but be safe). |
| 1079 | if (m > Prog::Inst::kMaxInst) |
| 1080 | m = Prog::Inst::kMaxInst; |
| 1081 | max_ninst_ = static_cast<int>(m); |
| 1082 | } |
| 1083 | anchor_ = anchor; |
| 1084 | } |
| 1085 | |
| 1086 | // Compiles re, returning program. |
| 1087 | // Caller is responsible for deleting prog_. |
no outgoing calls
no test coverage detected