CVS commit: src/bin/expr

2020-06-11 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Thu Jun 11 13:08:08 UTC 2020

Modified Files:
src/bin/expr: expr.y

Log Message:
Fix typo


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 src/bin/expr/expr.y

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/bin/expr/expr.y
diff -u src/bin/expr/expr.y:1.45 src/bin/expr/expr.y:1.46
--- src/bin/expr/expr.y:1.45	Wed Jun 27 17:23:36 2018
+++ src/bin/expr/expr.y	Thu Jun 11 13:08:07 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: expr.y,v 1.45 2018/06/27 17:23:36 kamil Exp $ */
+/* $NetBSD: expr.y,v 1.46 2020/06/11 13:08:07 kamil Exp $ */
 
 /*_
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 %{
 #include 
 #ifndef lint
-__RCSID("$NetBSD: expr.y,v 1.45 2018/06/27 17:23:36 kamil Exp $");
+__RCSID("$NetBSD: expr.y,v 1.46 2020/06/11 13:08:07 kamil Exp $");
 #endif /* not lint */
 
 #include 
@@ -361,7 +361,7 @@ perform_arith_op(const char *left, const
 			r = -r;
 		}
 
-		/* - remove the case of legative l and positive r */
+		/* - remove the case of negative l and positive r */
 		if (l < 0 && r >= 0) {
 			/* Use res as a temporary variable */
 			res = l;



CVS commit: src/bin/expr

2018-06-27 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed Jun 27 17:23:36 UTC 2018

Modified Files:
src/bin/expr: expr.y

Log Message:
Add a missing check to handle correctly 0 * 0 in expr(1)


To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 src/bin/expr/expr.y

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/bin/expr/expr.y
diff -u src/bin/expr/expr.y:1.44 src/bin/expr/expr.y:1.45
--- src/bin/expr/expr.y:1.44	Wed Jun 27 17:12:49 2018
+++ src/bin/expr/expr.y	Wed Jun 27 17:23:36 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: expr.y,v 1.44 2018/06/27 17:12:49 kamil Exp $ */
+/* $NetBSD: expr.y,v 1.45 2018/06/27 17:23:36 kamil Exp $ */
 
 /*_
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 %{
 #include 
 #ifndef lint
-__RCSID("$NetBSD: expr.y,v 1.44 2018/06/27 17:12:49 kamil Exp $");
+__RCSID("$NetBSD: expr.y,v 1.45 2018/06/27 17:23:36 kamil Exp $");
 #endif /* not lint */
 
 #include 
@@ -371,7 +371,7 @@ perform_arith_op(const char *left, const
 
 		if ((l < 0 && r < 0) ||
 		(r > 0 && l > INT64_MAX / r) ||
-		(r <= 0 && r < INT64_MIN / l)) {
+		(r <= 0 && l != 0 && r < INT64_MIN / l)) {
 			yyerror("integer overflow or underflow occurred for "
 			"operation '%s %s %s'", left, op, right);
 			/* NOTREACHED */



CVS commit: src/bin/expr

2018-06-27 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed Jun 27 17:12:50 UTC 2018

Modified Files:
src/bin/expr: expr.y

Log Message:
Improve the * operator handling in expr(1)

Fixes overflow detection in expressions INT * -UINT.

Detected with libFuzzer & UBSan.


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 src/bin/expr/expr.y

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/bin/expr/expr.y
diff -u src/bin/expr/expr.y:1.43 src/bin/expr/expr.y:1.44
--- src/bin/expr/expr.y:1.43	Thu Jun 14 02:46:56 2018
+++ src/bin/expr/expr.y	Wed Jun 27 17:12:49 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: expr.y,v 1.43 2018/06/14 02:46:56 christos Exp $ */
+/* $NetBSD: expr.y,v 1.44 2018/06/27 17:12:49 kamil Exp $ */
 
 /*_
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 %{
 #include 
 #ifndef lint
-__RCSID("$NetBSD: expr.y,v 1.43 2018/06/14 02:46:56 christos Exp $");
+__RCSID("$NetBSD: expr.y,v 1.44 2018/06/27 17:12:49 kamil Exp $");
 #endif /* not lint */
 
 #include 
@@ -351,17 +351,27 @@ perform_arith_op(const char *left, const
 		 * Check for over-& underflow.
 		 */
 
-		/* Simplify the conditions */
+		/*
+		 * Simplify the conditions:
+		 *  - remove the case of both negative arguments
+		 *unless the operation will cause an overflow
+		 */
 		if (l < 0 && r < 0 && l != INT64_MIN && r != INT64_MIN) {
 			l = -l;
 			r = -r;
 		}
 
+		/* - remove the case of legative l and positive r */
+		if (l < 0 && r >= 0) {
+			/* Use res as a temporary variable */
+			res = l;
+			l = r;
+			r = res;
+		}
+
 		if ((l < 0 && r < 0) ||
-		((l != 0 && r != 0) &&
-		 (((l > 0 && r > 0) && (l > INT64_MAX / r)) ||
-		 l < 0 && r > 0) || (l > 0 && r < 0)) &&
-		  (r != -1 && (l < INT64_MIN / r))) {
+		(r > 0 && l > INT64_MAX / r) ||
+		(r <= 0 && r < INT64_MIN / l)) {
 			yyerror("integer overflow or underflow occurred for "
 			"operation '%s %s %s'", left, op, right);
 			/* NOTREACHED */



CVS commit: src/bin/expr

2018-06-13 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Jun 14 02:46:56 UTC 2018

Modified Files:
src/bin/expr: expr.y

Log Message:
remove notreached


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 src/bin/expr/expr.y

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/bin/expr/expr.y
diff -u src/bin/expr/expr.y:1.42 src/bin/expr/expr.y:1.43
--- src/bin/expr/expr.y:1.42	Wed Jun 13 22:44:16 2018
+++ src/bin/expr/expr.y	Wed Jun 13 22:46:56 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: expr.y,v 1.42 2018/06/14 02:44:16 christos Exp $ */
+/* $NetBSD: expr.y,v 1.43 2018/06/14 02:46:56 christos Exp $ */
 
 /*_
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 %{
 #include 
 #ifndef lint
-__RCSID("$NetBSD: expr.y,v 1.42 2018/06/14 02:44:16 christos Exp $");
+__RCSID("$NetBSD: expr.y,v 1.43 2018/06/14 02:46:56 christos Exp $");
 #endif /* not lint */
 
 #include 
@@ -454,5 +454,4 @@ main(int argc, const char * const *argv)
 	av = argv + 1;
 
 	return yyparse();
-	/* NOTREACHED */
 }



CVS commit: src/bin/expr

2018-06-13 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Jun 14 02:44:16 UTC 2018

Modified Files:
src/bin/expr: expr.y

Log Message:
return to caller instead of exit(2)


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 src/bin/expr/expr.y

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/bin/expr/expr.y
diff -u src/bin/expr/expr.y:1.41 src/bin/expr/expr.y:1.42
--- src/bin/expr/expr.y:1.41	Wed Jun 13 13:35:15 2018
+++ src/bin/expr/expr.y	Wed Jun 13 22:44:16 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: expr.y,v 1.41 2018/06/13 17:35:15 kamil Exp $ */
+/* $NetBSD: expr.y,v 1.42 2018/06/14 02:44:16 christos Exp $ */
 
 /*_
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 %{
 #include 
 #ifndef lint
-__RCSID("$NetBSD: expr.y,v 1.41 2018/06/13 17:35:15 kamil Exp $");
+__RCSID("$NetBSD: expr.y,v 1.42 2018/06/14 02:44:16 christos Exp $");
 #endif /* not lint */
 
 #include 
@@ -453,6 +453,6 @@ main(int argc, const char * const *argv)
 
 	av = argv + 1;
 
-	exit(yyparse());
+	return yyparse();
 	/* NOTREACHED */
 }



CVS commit: src/bin/expr

2018-06-13 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed Jun 13 17:35:15 UTC 2018

Modified Files:
src/bin/expr: expr.y

Log Message:
Detect properly overflow in expr(1) for 0 + INT


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/bin/expr/expr.y

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/bin/expr/expr.y
diff -u src/bin/expr/expr.y:1.40 src/bin/expr/expr.y:1.41
--- src/bin/expr/expr.y:1.40	Tue Jun 12 18:12:18 2018
+++ src/bin/expr/expr.y	Wed Jun 13 17:35:15 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: expr.y,v 1.40 2018/06/12 18:12:18 kamil Exp $ */
+/* $NetBSD: expr.y,v 1.41 2018/06/13 17:35:15 kamil Exp $ */
 
 /*_
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 %{
 #include 
 #ifndef lint
-__RCSID("$NetBSD: expr.y,v 1.40 2018/06/12 18:12:18 kamil Exp $");
+__RCSID("$NetBSD: expr.y,v 1.41 2018/06/13 17:35:15 kamil Exp $");
 #endif /* not lint */
 
 #include 
@@ -309,8 +309,8 @@ perform_arith_op(const char *left, const
 		/*
 		 * Check for over-& underflow.
 		 */
-		if ((l > 0 && r <= INT64_MAX - l) ||
-		(l < 0 && r >= INT64_MIN - l)) {
+		if ((l >= 0 && r <= INT64_MAX - l) ||
+		(l <= 0 && r >= INT64_MIN - l)) {
 			res = l + r;
 		} else {
 			yyerror("integer overflow or underflow occurred for "



CVS commit: src/bin/expr

2018-06-12 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Tue Jun 12 18:12:18 UTC 2018

Modified Files:
src/bin/expr: expr.y

Log Message:
Rework perform_arith_op() in expr(1) to omit Undefined Behavior

The current implementation of operations - + * / % could cause Undefined
Behavior and in narrow cases (INT64_MIN / -1 and INT64_MIN % -1) SIGFPE
and crash duping core.

Detected with MKSANITIZER enabled for the Undefined Behavior variation:
# eval expr '4611686018427387904 + 4611686018427387904'
/public/src.git/bin/expr/expr.y:315:12: runtime error: signed integer overflow: 
4611686018427387904 + 4611686018427387904 cannot be represented in type 'long'

All bin/t_expr ATF tests pass now in a sanitized userland.

Sponsored by 


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 src/bin/expr/expr.y

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/bin/expr/expr.y
diff -u src/bin/expr/expr.y:1.39 src/bin/expr/expr.y:1.40
--- src/bin/expr/expr.y:1.39	Mon Sep  5 01:00:07 2016
+++ src/bin/expr/expr.y	Tue Jun 12 18:12:18 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: expr.y,v 1.39 2016/09/05 01:00:07 sevan Exp $ */
+/* $NetBSD: expr.y,v 1.40 2018/06/12 18:12:18 kamil Exp $ */
 
 /*_
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 %{
 #include 
 #ifndef lint
-__RCSID("$NetBSD: expr.y,v 1.39 2016/09/05 01:00:07 sevan Exp $");
+__RCSID("$NetBSD: expr.y,v 1.40 2018/06/12 18:12:18 kamil Exp $");
 #endif /* not lint */
 
 #include 
@@ -273,8 +273,7 @@ is_integer(const char *str)
 static int64_t
 perform_arith_op(const char *left, const char *op, const char *right)
 {
-	int64_t res, sign, l, r;
-	u_int64_t temp;
+	int64_t res, l, r;
 
 	res = 0;
 
@@ -307,66 +306,68 @@ perform_arith_op(const char *left, const
 
 	switch(op[0]) {
 	case '+':
-		/* 
-		 * Do the op into an unsigned to avoid overflow and then cast
-		 * back to check the resulting signage. 
+		/*
+		 * Check for over-& underflow.
 		 */
-		temp = l + r;
-		res = (int64_t) temp;
-		/* very simplistic check for over-& underflow */
-		if ((res < 0 && l > 0 && r > 0)
-	  	|| (res > 0 && l < 0 && r < 0)) 
+		if ((l > 0 && r <= INT64_MAX - l) ||
+		(l < 0 && r >= INT64_MIN - l)) {
+			res = l + r;
+		} else {
 			yyerror("integer overflow or underflow occurred for "
 "operation '%s %s %s'", left, op, right);
+		}
 		break;
 	case '-':
-		/* 
-		 * Do the op into an unsigned to avoid overflow and then cast
-		 * back to check the resulting signage. 
+		/*
+		 * Check for over-& underflow.
 		 */
-		temp = l - r;
-		res = (int64_t) temp;
-		/* very simplistic check for over-& underflow */
-		if ((res < 0 && l > 0 && l > r)
-		|| (res > 0 && l < 0 && l < r) ) 
+		if ((r > 0 && l < INT64_MIN + r) ||
+		(r < 0 && l > INT64_MAX + r)) {
 			yyerror("integer overflow or underflow occurred for "
 			"operation '%s %s %s'", left, op, right);
+		} else {
+			res = l - r;
+		}
 		break;
 	case '/':
-		if (r == 0) 
+		if (r == 0)
 			yyerror("second argument to '%s' must not be zero", op);
+		if (l == INT64_MIN && r == -1)
+			yyerror("integer overflow or underflow occurred for "
+			"operation '%s %s %s'", left, op, right);
 		res = l / r;
 			
 		break;
 	case '%':
 		if (r == 0)
 			yyerror("second argument to '%s' must not be zero", op);
+		if (l == INT64_MIN && r == -1)
+			yyerror("integer overflow or underflow occurred for "
+			"operation '%s %s %s'", left, op, right);
 		res = l % r;
 		break;
 	case '*':
-		/* shortcut */
-		if ((l == 0) || (r == 0)) {
-			res = 0;
-			break;
-		}
-
-		sign = 1;
-		if (l < 0)
-			sign *= -1;
-		if (r < 0)
-			sign *= -1;
-
-		res = l * r;
 		/*
-		 * XXX: not the most portable but works on anything with 2's
-		 * complement arithmetic. If the signs don't match or the
-		 * result was 0 on 2's complement this overflowed.
+		 * Check for over-& underflow.
 		 */
-		if ((res < 0 && sign > 0) || (res > 0 && sign < 0) || 
-		(res == 0))
+
+		/* Simplify the conditions */
+		if (l < 0 && r < 0 && l != INT64_MIN && r != INT64_MIN) {
+			l = -l;
+			r = -r;
+		}
+
+		if ((l < 0 && r < 0) ||
+		((l != 0 && r != 0) &&
+		 (((l > 0 && r > 0) && (l > INT64_MAX / r)) ||
+		 l < 0 && r > 0) || (l > 0 && r < 0)) &&
+		  (r != -1 && (l < INT64_MIN / r))) {
 			yyerror("integer overflow or underflow occurred for "
 			"operation '%s %s %s'", left, op, right);
 			/* NOTREACHED */
+		} else {
+			res = l * r;
+		}
 		break;
 	}
 	return res;



CVS commit: src/bin/expr

2016-08-23 Thread Sevan Janiyan
Module Name:src
Committed By:   sevan
Date:   Tue Aug 23 20:34:23 UTC 2016

Modified Files:
src/bin/expr: expr.1

Log Message:
Mark email addresses as mailto links, heads up by Sascha Wildner.
Move email addresses to same line as author name.
Do not split the third author entry on to a new line.
Public domain is not licensed by definition, heads up by Robert Elz.


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/bin/expr/expr.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/bin/expr/expr.1
diff -u src/bin/expr/expr.1:1.35 src/bin/expr/expr.1:1.36
--- src/bin/expr/expr.1:1.35	Tue Aug 23 03:21:16 2016
+++ src/bin/expr/expr.1	Tue Aug 23 20:34:23 2016
@@ -1,4 +1,4 @@
-.\"	$NetBSD: expr.1,v 1.35 2016/08/23 03:21:16 sevan Exp $
+.\"	$NetBSD: expr.1,v 1.36 2016/08/23 20:34:23 sevan Exp $
 .\"
 .\" Copyright (c) 2000,2003 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -246,7 +246,7 @@ keyword is an extension for compatibilit
 An
 .Nm
 utility first appeared in the Programmer's Workbench (PWB/UNIX).
-A public domain licensed version of
+A public domain version of
 .Nm
 written by
 .An Pace Willisson
@@ -255,17 +255,15 @@ appeared in
 .Bx 386 0.1 .
 .Sh AUTHORS
 Initial implementation by
-.An Pace Willisson
-.Aq p...@blitz.com
+.An Pace Willisson Aq Mt p...@blitz.com
 was largely rewritten by
 .An -nosplit
-.An J.T. Conklin
-.Aq j...@netbsd.org .
+.An J.T. Conklin Aq Mt j...@netbsd.org .
 It was rewritten again for
 .Nx 1.6
 by
-.An Jaromir Dolecek
-.Aq jdole...@netbsd.org .
+.An -nosplit
+.An Jaromir Dolecek Aq Mt jdole...@netbsd.org .
 .Sh NOTES
 The empty string
 .Do Dc



CVS commit: src/bin/expr

2016-08-22 Thread Sevan Janiyan
Module Name:src
Committed By:   sevan
Date:   Tue Aug 23 03:21:16 UTC 2016

Modified Files:
src/bin/expr: expr.1

Log Message:
Instruction to not split the line needs to be stated separately.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/bin/expr/expr.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/bin/expr/expr.1
diff -u src/bin/expr/expr.1:1.34 src/bin/expr/expr.1:1.35
--- src/bin/expr/expr.1:1.34	Tue Aug 23 02:58:45 2016
+++ src/bin/expr/expr.1	Tue Aug 23 03:21:16 2016
@@ -1,4 +1,4 @@
-.\"	$NetBSD: expr.1,v 1.34 2016/08/23 02:58:45 sevan Exp $
+.\"	$NetBSD: expr.1,v 1.35 2016/08/23 03:21:16 sevan Exp $
 .\"
 .\" Copyright (c) 2000,2003 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -258,7 +258,8 @@ Initial implementation by
 .An Pace Willisson
 .Aq p...@blitz.com
 was largely rewritten by
-.An -nosplit J.T. Conklin
+.An -nosplit
+.An J.T. Conklin
 .Aq j...@netbsd.org .
 It was rewritten again for
 .Nx 1.6



CVS commit: src/bin/expr

2016-08-22 Thread Sevan Janiyan
Module Name:src
Committed By:   sevan
Date:   Tue Aug 23 02:58:45 UTC 2016

Modified Files:
src/bin/expr: expr.1

Log Message:
Add HISTORY section
Credit author of initial implementation in AUTHORS section
Bump date
Remove contraction highlighted by textproc/igor


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/bin/expr/expr.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/bin/expr/expr.1
diff -u src/bin/expr/expr.1:1.33 src/bin/expr/expr.1:1.34
--- src/bin/expr/expr.1:1.33	Sun Aug 12 17:27:04 2012
+++ src/bin/expr/expr.1	Tue Aug 23 02:58:45 2016
@@ -1,4 +1,4 @@
-.\"	$NetBSD: expr.1,v 1.33 2012/08/12 17:27:04 wiz Exp $
+.\"	$NetBSD: expr.1,v 1.34 2016/08/23 02:58:45 sevan Exp $
 .\"
 .\" Copyright (c) 2000,2003 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -27,7 +27,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd April 20, 2004
+.Dd August 23, 2016
 .Dt EXPR 1
 .Os
 .Sh NAME
@@ -214,7 +214,7 @@ treat it as a delimiter to mark the end 
 line options, and ignore it.
 Some
 .Nm
-implementations don't recognize it at all; others
+implementations do not recognize it at all; others
 might ignore it even in cases where doing so results in syntax
 error.
 There should be same result for both following examples,
@@ -242,11 +242,25 @@ The
 .Ar length
 keyword is an extension for compatibility with GNU
 .Nm .
+.Sh HISTORY
+An
+.Nm
+utility first appeared in the Programmer's Workbench (PWB/UNIX).
+A public domain licensed version of
+.Nm
+written by
+.An Pace Willisson
+.Aq p...@blitz.com
+appeared in
+.Bx 386 0.1 .
 .Sh AUTHORS
-Original implementation was written by
-.An J.T. Conklin
+Initial implementation by
+.An Pace Willisson
+.Aq p...@blitz.com
+was largely rewritten by
+.An -nosplit J.T. Conklin
 .Aq j...@netbsd.org .
-It was rewritten for
+It was rewritten again for
 .Nx 1.6
 by
 .An Jaromir Dolecek



CVS commit: src/bin/expr

2016-04-01 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Fri Apr  1 08:19:32 UTC 2016

Modified Files:
src/bin/expr: Makefile

Log Message:
for GCC 5.3 pass -fwrapv as this relies upon well-defined integer overflow.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/bin/expr/Makefile

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/bin/expr/Makefile
diff -u src/bin/expr/Makefile:1.14 src/bin/expr/Makefile:1.15
--- src/bin/expr/Makefile:1.14	Tue Sep 19 17:20:00 2000
+++ src/bin/expr/Makefile	Fri Apr  1 08:19:31 2016
@@ -1,6 +1,12 @@
-#	$NetBSD: Makefile,v 1.14 2000/09/19 17:20:00 jdolecek Exp $
+#	$NetBSD: Makefile,v 1.15 2016/04/01 08:19:31 mrg Exp $
 
 PROG=		expr
 SRCS=		expr.y
 
 .include 
+
+# XXXGCC5
+.if defined(HAVE_GCC) && ${HAVE_GCC} == 53 && ${ACTIVE_CC} == "gcc"
+CFLAGS+= -fwrapv
+.endif
+



CVS commit: src/bin/expr

2012-08-12 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Sun Aug 12 17:27:05 UTC 2012

Modified Files:
src/bin/expr: expr.1

Log Message:
Improvements: wording, punctuation, macro usage.

From patch by Bug Hunting.


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/bin/expr/expr.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/bin/expr/expr.1
diff -u src/bin/expr/expr.1:1.32 src/bin/expr/expr.1:1.33
--- src/bin/expr/expr.1:1.32	Wed May  9 22:29:06 2012
+++ src/bin/expr/expr.1	Sun Aug 12 17:27:04 2012
@@ -1,4 +1,4 @@
-.\	$NetBSD: expr.1,v 1.32 2012/05/09 22:29:06 jdf Exp $
+.\	$NetBSD: expr.1,v 1.33 2012/08/12 17:27:04 wiz Exp $
 .\
 .\ Copyright (c) 2000,2003 The NetBSD Foundation, Inc.
 .\ All rights reserved.
@@ -145,18 +145,23 @@ an error occurred (such as memory alloca
 .Sh EXAMPLES
 .Bl -enum
 .It
-The following example adds one to the variable a.
+The following example adds one to variable
+.Dq a :
 .Dl a=`expr $a + 1`
 .It
 The following example returns zero, due to subtraction having higher precedence
-than '\*[Am]' operator.
+than the
+.Dq \*[Am]
+operator:
 .Dl expr 1 '\*[Am]' 1 - 1
 .It
 The following example returns the filename portion of a pathname stored
-in variable a.
+in variable
+.Dq a :
 .Dl expr /$a Li : '.*/\e(.*\e)'
 .It
-The following example returns the number of characters in variable a.
+The following example returns the number of characters in variable
+.Dq a :
 .Dl expr $a Li : '.*'
 .El
 .Sh COMPATIBILITY
@@ -164,8 +169,11 @@ This implementation of
 .Nm
 internally uses 64 bit representation of integers and checks for
 over- and underflows.
-It also treats / (division mark) and
-option '--' correctly depending upon context.
+It also treats
+.Dq /
+(the division mark) and option
+.Dq --
+correctly depending upon context.
 .Pp
 .Nm
 on other systems (including
@@ -182,12 +190,16 @@ can only process values between -2147483
 On other systems,
 .Nm
 might also not work correctly for regular expressions where
-either side contains single forward slash, like this:
+either side contains
+.Dq /
+(a single forward slash), like this:
 .Bd -literal -offset indent
 expr / : '.*/\e(.*\e)'
 .Ed
 .Pp
-If this is the case, you might use // (double forward slash)
+If this is the case, you might use
+.Dq //
+(a double forward slash)
 to avoid confusion with the division operator:
 .Bd -literal -offset indent
 expr //$a : '.*/\e(.*\e)'
@@ -196,11 +208,13 @@ expr //$a : '.*/\e(.*\e)'
 According to
 .St -p1003.2 ,
 .Nm
-has to recognize special option '--', treat it as an end of command
-line options and ignore it.
+has to recognize special option
+.Dq -- ,
+treat it as a delimiter to mark the end of command
+line options, and ignore it.
 Some
 .Nm
-implementations don't recognize it at all, others
+implementations don't recognize it at all; others
 might ignore it even in cases where doing so results in syntax
 error.
 There should be same result for both following examples,
@@ -215,7 +229,9 @@ Although
 .Nx
 .Nm
 handles both cases correctly, you should not depend on this behavior
-for portability reasons and avoid passing bare '--' as first
+for portability reasons and avoid passing a bare
+.Dq --
+as the first
 argument.
 .Sh STANDARDS
 The



CVS commit: src/bin/expr

2012-05-09 Thread Julian Fagir
Module Name:src
Committed By:   jdf
Date:   Wed May  9 22:29:06 UTC 2012

Modified Files:
src/bin/expr: expr.1

Log Message:
Remove an unnecessary space in the manpage.  Patch provided by Bug Hunting.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/bin/expr/expr.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/bin/expr/expr.1
diff -u src/bin/expr/expr.1:1.31 src/bin/expr/expr.1:1.32
--- src/bin/expr/expr.1:1.31	Wed Mar 23 18:10:25 2011
+++ src/bin/expr/expr.1	Wed May  9 22:29:06 2012
@@ -1,4 +1,4 @@
-.\	$NetBSD: expr.1,v 1.31 2011/03/23 18:10:25 dholland Exp $
+.\	$NetBSD: expr.1,v 1.32 2012/05/09 22:29:06 jdf Exp $
 .\
 .\ Copyright (c) 2000,2003 The NetBSD Foundation, Inc.
 .\ All rights reserved.
@@ -81,7 +81,7 @@ against
 .Ar expr2 ,
 which must be a regular expression.
 The regular expression is anchored
-to the beginning of  the string with an implicit
+to the beginning of the string with an implicit
 .Dq ^ .
 .Pp
 If the match succeeds and the pattern contains at least one regular



CVS commit: src/bin/expr

2011-08-24 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Thu Aug 25 01:11:48 UTC 2011

Modified Files:
src/bin/expr: expr.y

Log Message:
Mark yyerror as dead.


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/bin/expr/expr.y

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/bin/expr/expr.y
diff -u src/bin/expr/expr.y:1.36 src/bin/expr/expr.y:1.37
--- src/bin/expr/expr.y:1.36	Tue Jan 20 14:22:37 2009
+++ src/bin/expr/expr.y	Thu Aug 25 01:11:47 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: expr.y,v 1.36 2009/01/20 14:22:37 joerg Exp $ */
+/* $NetBSD: expr.y,v 1.37 2011/08/25 01:11:47 joerg Exp $ */
 
 /*_
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 %{
 #include sys/cdefs.h
 #ifndef lint
-__RCSID($NetBSD: expr.y,v 1.36 2009/01/20 14:22:37 joerg Exp $);
+__RCSID($NetBSD: expr.y,v 1.37 2011/08/25 01:11:47 joerg Exp $);
 #endif /* not lint */
 
 #include sys/types.h
@@ -49,7 +49,7 @@
 
 static const char * const *av;
 
-static void yyerror(const char *, ...);
+static void yyerror(const char *, ...) __dead;
 static int yylex(void);
 static int is_zero_or_null(const char *);
 static int is_integer(const char *);



CVS commit: src/bin/expr

2011-03-23 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Wed Mar 23 18:10:25 UTC 2011

Modified Files:
src/bin/expr: expr.1

Log Message:
minor usage nit


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/bin/expr/expr.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/bin/expr/expr.1
diff -u src/bin/expr/expr.1:1.30 src/bin/expr/expr.1:1.31
--- src/bin/expr/expr.1:1.30	Mon May 24 00:29:30 2010
+++ src/bin/expr/expr.1	Wed Mar 23 18:10:25 2011
@@ -1,4 +1,4 @@
-.\	$NetBSD: expr.1,v 1.30 2010/05/24 00:29:30 joerg Exp $
+.\	$NetBSD: expr.1,v 1.31 2011/03/23 18:10:25 dholland Exp $
 .\
 .\ Copyright (c) 2000,2003 The NetBSD Foundation, Inc.
 .\ All rights reserved.
@@ -148,7 +148,7 @@
 The following example adds one to the variable a.
 .Dl a=`expr $a + 1`
 .It
-The following example returns zero, due to deduction having higher precedence
+The following example returns zero, due to subtraction having higher precedence
 than '\*[Am]' operator.
 .Dl expr 1 '\*[Am]' 1 - 1
 .It



CVS commit: src/bin/expr

2010-05-23 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Mon May 24 00:29:30 UTC 2010

Modified Files:
src/bin/expr: expr.1

Log Message:
Explicitly quote | and : meant as separate operator. Kill trailing
whitespace. Don't use \Z' with obscure character entity. Reorder sections
to canonical order.


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/bin/expr/expr.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/bin/expr/expr.1
diff -u src/bin/expr/expr.1:1.29 src/bin/expr/expr.1:1.30
--- src/bin/expr/expr.1:1.29	Wed Apr 30 13:10:46 2008
+++ src/bin/expr/expr.1	Mon May 24 00:29:30 2010
@@ -1,4 +1,4 @@
-.\	$NetBSD: expr.1,v 1.29 2008/04/30 13:10:46 martin Exp $
+.\	$NetBSD: expr.1,v 1.30 2010/05/24 00:29:30 joerg Exp $
 .\
 .\ Copyright (c) 2000,2003 The NetBSD Foundation, Inc.
 .\ All rights reserved.
@@ -51,7 +51,7 @@
 Operators are listed below in order of increasing precedence.
 Operators with equal precedence are grouped within { } symbols.
 .Bl -tag -width indent
-.It Ar expr1 Li | Ar expr2
+.It Ar expr1 Li \| Ar expr2
 Returns the evaluation of
 .Ar expr1
 if it is neither an empty string nor zero;
@@ -72,7 +72,7 @@
 Returns the results of addition or subtraction of integer-valued arguments.
 .It Ar expr1 Li {*, /, %} Ar expr2
 Returns the results of multiplication, integer division, or remainder of integer-valued arguments.
-.It Ar expr1 Li : Ar expr2
+.It Ar expr1 Li \: Ar expr2
 The
 .Dq \:
 operator matches
@@ -100,7 +100,7 @@
 .Pp
 Additionally, the following keywords are recognized:
 .Bl -tag -width indent
-.It length Ar expr 
+.It length Ar expr
 Returns the length of the specified string in bytes.
 .El
 .Pp
@@ -126,7 +126,7 @@
 .It
 .Dq \*[Am]
 .It
-.Dq \Z'\*[tty-rn]'|
+.Dq \|
 .El
 .Sh EXIT STATUS
 The
@@ -159,38 +159,6 @@
 The following example returns the number of characters in variable a.
 .Dl expr $a Li : '.*'
 .El
-.Sh STANDARDS
-The
-.Nm
-utility conforms to
-.St -p1003.2 .
-The
-.Ar length
-keyword is an extension for compatibility with GNU
-.Nm .
-.Sh AUTHORS
-Original implementation was written by
-.An J.T. Conklin
-.Aq j...@netbsd.org .
-It was rewritten for
-.Nx 1.6
-by
-.An Jaromir Dolecek
-.Aq jdole...@netbsd.org .
-.Sh NOTES
-The empty string
-.Dq
-cannot be matched with the intuitive:
-.Bd -literal -offset indent
-expr '' : '$'
-.Ed
-.Pp
-The reason is that the returned number of matched characters (zero)
-is indistinguishable from a failed match, so this returns failure.
-To match the empty string, use something like:
-.Bd -literal -offset indent
-expr x'' : 'x$'
-.Ed
 .Sh COMPATIBILITY
 This implementation of
 .Nm
@@ -249,3 +217,35 @@
 handles both cases correctly, you should not depend on this behavior
 for portability reasons and avoid passing bare '--' as first
 argument.
+.Sh STANDARDS
+The
+.Nm
+utility conforms to
+.St -p1003.2 .
+The
+.Ar length
+keyword is an extension for compatibility with GNU
+.Nm .
+.Sh AUTHORS
+Original implementation was written by
+.An J.T. Conklin
+.Aq j...@netbsd.org .
+It was rewritten for
+.Nx 1.6
+by
+.An Jaromir Dolecek
+.Aq jdole...@netbsd.org .
+.Sh NOTES
+The empty string
+.Do Dc
+cannot be matched with the intuitive:
+.Bd -literal -offset indent
+expr '' : '$'
+.Ed
+.Pp
+The reason is that the returned number of matched characters (zero)
+is indistinguishable from a failed match, so this returns failure.
+To match the empty string, use something like:
+.Bd -literal -offset indent
+expr x'' : 'x$'
+.Ed