10
10
#define INSERT_CODE (at , num , pc ) \
11
11
((code ? memmove(code + at + num, code + at, pc - at) : 0), pc += num)
12
12
#define REL (at , to ) (to - at - 2)
13
- #define EMIT (at , byte ) ( code ? (code[at ] = byte) : (at))
13
+ #define EMIT (at , byte ) {int _at = at; code ? (code[_at ] = byte) : (0);}
14
14
#define EMIT_CHECKED (at , byte ) (_emit_checked(at, code, byte, &err))
15
15
#define PC (prog->bytelen)
16
16
@@ -29,8 +29,9 @@ static const char *_compilecode(const char *re, size_t len, ByteProg *prog, int
29
29
int term = PC ;
30
30
int alt_label = 0 ;
31
31
const char * re_top = re + len ;
32
-
33
- while (re < re_top && * re != ')' ) {
32
+ int remain ;
33
+
34
+ while ((remain = re_top - re ) && * re != ')' ) {
34
35
switch (* re ) {
35
36
case '\\' :
36
37
re ++ ;
@@ -80,8 +81,7 @@ static const char *_compilecode(const char *re, size_t len, ByteProg *prog, int
80
81
goto emit_char_pair ;
81
82
}
82
83
}
83
- if (!c ) return NULL ;
84
- if (re_top - re > 2 && re [1 ] == '-' && re [2 ] != ']' ) {
84
+ if (remain > 2 && re [1 ] == '-' && re [2 ] != ']' ) {
85
85
re += 2 ;
86
86
}
87
87
emit_char_pair :
@@ -94,7 +94,7 @@ static const char *_compilecode(const char *re, size_t len, ByteProg *prog, int
94
94
case '(' : {
95
95
term = PC ;
96
96
int sub = 0 ;
97
- int capture = re_top - re > 2 && (re [1 ] != '?' || re [2 ] != ':' );
97
+ int capture = remain > 2 && (re [1 ] != '?' || re [2 ] != ':' );
98
98
99
99
if (capture ) {
100
100
sub = ++ prog -> sub ;
@@ -107,8 +107,8 @@ static const char *_compilecode(const char *re, size_t len, ByteProg *prog, int
107
107
108
108
re ++ ;
109
109
if (re >= re_top ) return NULL ; // Trailing bracket
110
- re = _compilecode (re , re_top - re , prog , sizecode );
111
- if (re == NULL || re >= re_top || * re != ')' ) return NULL ; // error, or no matching paren
110
+ re = _compilecode (re , remain , prog , sizecode );
111
+ if (re == NULL || * re != ')' ) return NULL ; // error, or no matching paren
112
112
113
113
if (capture ) {
114
114
EMIT (PC ++ , Save );
@@ -121,7 +121,7 @@ static const char *_compilecode(const char *re, size_t len, ByteProg *prog, int
121
121
case '?' :
122
122
if (PC == term ) return NULL ; // nothing to repeat
123
123
INSERT_CODE (term , 2 , PC );
124
- if (re_top - re > 1 && re [1 ] == '?' ) {
124
+ if (remain > 1 && re [1 ] == '?' ) {
125
125
EMIT (term , RSplit );
126
126
re ++ ;
127
127
} else {
@@ -137,7 +137,7 @@ static const char *_compilecode(const char *re, size_t len, ByteProg *prog, int
137
137
EMIT (PC , Jmp );
138
138
EMIT_CHECKED (PC + 1 , REL (PC , term ));
139
139
PC += 2 ;
140
- if (re_top - re > 1 && re [1 ] == '?' ) {
140
+ if (remain > 1 && re [1 ] == '?' ) {
141
141
EMIT (term , RSplit );
142
142
re ++ ;
143
143
} else {
@@ -149,7 +149,7 @@ static const char *_compilecode(const char *re, size_t len, ByteProg *prog, int
149
149
break ;
150
150
case '+' :
151
151
if (PC == term ) return NULL ; // nothing to repeat
152
- if (re_top - re > 1 && re [1 ] == '?' ) {
152
+ if (remain > 1 && re [1 ] == '?' ) {
153
153
EMIT (PC , Split );
154
154
re ++ ;
155
155
} else {
0 commit comments