Date: Mon, 07 Jul 2014 19:12:21 +0000 From: bugzilla-noreply@freebsd.org To: freebsd-bugs@FreeBSD.org Subject: [Bug 191719] New: bin/expr doesn't detect some overflow errors with multiplication Message-ID: <bug-191719-8@https.bugs.freebsd.org/bugzilla/>
next in thread | raw e-mail | index | archive | help
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=191719 Bug ID: 191719 Summary: bin/expr doesn't detect some overflow errors with multiplication Product: Base System Version: 11.0-CURRENT Hardware: Any OS: Any Status: Needs Triage Severity: Affects Some People Priority: --- Component: bin Assignee: freebsd-bugs@FreeBSD.org Reporter: yaneurabeya@gmail.com If I do the following case, it doesn't fail on FreeBSD like it does NetBSD: % expr -- -4611686018427387904 \* 3 4611686018427387904 # python2 -c 'print -4611686018427387904 * 3' -13835058055282163712 This is could be fixed by adding a signage check to assert_times, like what's in assert_plus: if the signage of two numbers is not the same, i.e. one is negative, the other is positive -- then the value must be negative. 395 void 396 assert_plus(intmax_t a, intmax_t b, intmax_t r) 397 { 398 /* 399 * sum of two positive numbers must be positive, 400 * sum of two negative numbers must be negative 401 */ 402 if ((a > 0 && b > 0 && r <= 0) || 403 (a < 0 && b < 0 && r >= 0)) 404 errx(ERR_EXIT, "overflow"); 405 } ... 447 void 448 assert_times(intmax_t a, intmax_t b, intmax_t r) 449 { 450 /* 451 * if first operand is 0, no overflow is possible, 452 * else result of division test must match second operand 453 */ 454 if (a != 0 && r / a != b) 455 errx(ERR_EXIT, "overflow"); 456 } -- You are receiving this mail because: You are the assignee for the bug.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-191719-8>