[Bug 191719] New: bin/expr doesn't detect some overflow errors with multiplication
bugzilla-noreply at freebsd.org
bugzilla-noreply at freebsd.org
Mon Jul 7 19:12:21 UTC 2014
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 at FreeBSD.org
Reporter: yaneurabeya at 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.
More information about the freebsd-bugs
mailing list