From 2537a420e6b50bc924cc26d3bda1cdbd084ec1c3 Mon Sep 17 00:00:00 2001 From: kamil Date: Wed, 13 Jun 2018 17:35:15 +0000 Subject: [PATCH] Detect properly overflow in expr(1) for 0 + INT --- bin/expr/expr.y | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/expr/expr.y b/bin/expr/expr.y index 12bc375df1f7..7d1260ebbe15 100644 --- a/bin/expr/expr.y +++ b/bin/expr/expr.y @@ -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 char *op, const char *right) /* * 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 "