Skip to content

Commit 7dfa81e

Browse files
committed
pass gawk's fsbs test by treating a dangling trailing "\" as a literal,
escaping it to work that way.
1 parent 6c73fd5 commit 7dfa81e

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

regexp_system.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* $MawkId: regexp_system.c,v 1.21 2010/06/24 23:34:06 tom Exp $
2+
* $MawkId: regexp_system.c,v 1.22 2010/06/25 00:24:50 tom Exp $
33
*/
44
#include <sys/types.h>
55
#include <stdio.h>
@@ -26,8 +26,10 @@ static int err_code = 0;
2626
#define TRACE(params) /*nothing */
2727
#endif
2828

29-
#define NEXT_CH() (char) (((size_t) (source - base) < limit) ? *source : 0)
30-
#define LIMITED() (char) (((size_t) (source - base) < limit) ? *source++ : 0)
29+
#define AT_LAST() ((size_t) (source + 1 - base) >= limit)
30+
#define MORE_CH() ((size_t) (source - base) < limit)
31+
#define NEXT_CH() (char) (MORE_CH() ? *source : 0)
32+
#define LIMITED() (char) (MORE_CH() ? *source++ : 0)
3133

3234
#define IgnoreNull() errmsg(-1, "ignoring embedded null in pattern")
3335

@@ -203,7 +205,12 @@ prepare_regexp(char *regexp, const char *source, size_t limit)
203205
} else {
204206
switch (ch) {
205207
case '\\':
206-
escape = 1;
208+
if (AT_LAST()) {
209+
*tail++ = '\\';
210+
*tail++ = '\\';
211+
} else {
212+
escape = 1;
213+
}
207214
break;
208215
case '[':
209216
if (range == 0) {

0 commit comments

Comments
 (0)