diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2009-03-03 14:27:36 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2009-03-03 14:27:36 +0000 |
commit | 230997bd61eec4096e6ae70850e965b63c8886cf (patch) | |
tree | c1dd800a7c22afe8de1efcca6aeac53263bdf0c5 | |
parent | 6852effbc22fa3e7fda34eff7bc245bd211e1287 (diff) | |
download | busybox-w32-230997bd61eec4096e6ae70850e965b63c8886cf.tar.gz busybox-w32-230997bd61eec4096e6ae70850e965b63c8886cf.tar.bz2 busybox-w32-230997bd61eec4096e6ae70850e965b63c8886cf.zip |
expr: a bit more robust handling of regexps with groups (closes bug 87)
-rw-r--r-- | coreutils/expr.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/coreutils/expr.c b/coreutils/expr.c index d659b670b..54c2ee165 100644 --- a/coreutils/expr.c +++ b/coreutils/expr.c | |||
@@ -223,13 +223,13 @@ static VALUE *docolon(VALUE *sv, VALUE *pv) | |||
223 | tostring(pv); | 223 | tostring(pv); |
224 | 224 | ||
225 | if (pv->u.s[0] == '^') { | 225 | if (pv->u.s[0] == '^') { |
226 | bb_error_msg("\ | 226 | bb_error_msg( |
227 | warning: unportable BRE: `%s': using `^' as the first character\n\ | 227 | "warning: '%s': using '^' as the first character\n" |
228 | of a basic regular expression is not portable; it is being ignored", pv->u.s); | 228 | "of a basic regular expression is not portable; it is ignored", pv->u.s); |
229 | } | 229 | } |
230 | 230 | ||
231 | memset(&re_buffer, 0, sizeof(re_buffer)); | 231 | memset(&re_buffer, 0, sizeof(re_buffer)); |
232 | memset(re_regs, 0, sizeof(*re_regs)); | 232 | memset(re_regs, 0, sizeof(re_regs)); |
233 | xregcomp(&re_buffer, pv->u.s, 0); | 233 | xregcomp(&re_buffer, pv->u.s, 0); |
234 | 234 | ||
235 | /* expr uses an anchored pattern match, so check that there was a | 235 | /* expr uses an anchored pattern match, so check that there was a |
@@ -238,7 +238,7 @@ of a basic regular expression is not portable; it is being ignored", pv->u.s); | |||
238 | && re_regs[0].rm_so == 0 | 238 | && re_regs[0].rm_so == 0 |
239 | ) { | 239 | ) { |
240 | /* Were \(...\) used? */ | 240 | /* Were \(...\) used? */ |
241 | if (re_buffer.re_nsub > 0) { | 241 | if (re_buffer.re_nsub > 0 && re_regs[1].rm_so >= 0) { |
242 | sv->u.s[re_regs[1].rm_eo] = '\0'; | 242 | sv->u.s[re_regs[1].rm_eo] = '\0'; |
243 | v = str_value(sv->u.s + re_regs[1].rm_so); | 243 | v = str_value(sv->u.s + re_regs[1].rm_so); |
244 | } else { | 244 | } else { |
@@ -251,7 +251,7 @@ of a basic regular expression is not portable; it is being ignored", pv->u.s); | |||
251 | else | 251 | else |
252 | v = int_value(0); | 252 | v = int_value(0); |
253 | } | 253 | } |
254 | //FIXME: sounds like here is a bit missing: regfree(&re_buffer); | 254 | regfree(&re_buffer); |
255 | return v; | 255 | return v; |
256 | } | 256 | } |
257 | 257 | ||