svn commit: trunk/busybox/coreutils

vda at busybox.net vda at busybox.net
Tue Mar 3 14:27:37 UTC 2009


Author: vda
Date: 2009-03-03 14:27:36 +0000 (Tue, 03 Mar 2009)
New Revision: 25507

Log:
expr: a bit more robust handling of regexps with groups (closes bug 87)



Modified:
   trunk/busybox/coreutils/expr.c


Changeset:
Modified: trunk/busybox/coreutils/expr.c
===================================================================
--- trunk/busybox/coreutils/expr.c	2009-03-03 14:14:44 UTC (rev 25506)
+++ trunk/busybox/coreutils/expr.c	2009-03-03 14:27:36 UTC (rev 25507)
@@ -223,13 +223,13 @@
 	tostring(pv);
 
 	if (pv->u.s[0] == '^') {
-		bb_error_msg("\
-warning: unportable BRE: `%s': using `^' as the first character\n\
-of a basic regular expression is not portable; it is being ignored", pv->u.s);
+		bb_error_msg(
+"warning: '%s': using '^' as the first character\n"
+"of a basic regular expression is not portable; it is ignored", pv->u.s);
 	}
 
 	memset(&re_buffer, 0, sizeof(re_buffer));
-	memset(re_regs, 0, sizeof(*re_regs));
+	memset(re_regs, 0, sizeof(re_regs));
 	xregcomp(&re_buffer, pv->u.s, 0);
 
 	/* expr uses an anchored pattern match, so check that there was a
@@ -238,7 +238,7 @@
 	 && re_regs[0].rm_so == 0
 	) {
 		/* Were \(...\) used? */
-		if (re_buffer.re_nsub > 0) {
+		if (re_buffer.re_nsub > 0 && re_regs[1].rm_so >= 0) {
 			sv->u.s[re_regs[1].rm_eo] = '\0';
 			v = str_value(sv->u.s + re_regs[1].rm_so);
 		} else {
@@ -251,7 +251,7 @@
 		else
 			v = int_value(0);
 	}
-//FIXME: sounds like here is a bit missing: regfree(&re_buffer);
+	regfree(&re_buffer);
 	return v;
 }
 



More information about the busybox-cvs mailing list