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 <sys/cdefs.h>
 #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 <sys/types.h>
@@ -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 "

Reply via email to