# HG changeset patch # User Aidan Kehoe # Date 1428523398 -3600 # Node ID c96000075e496610e75de4929b04d1c5eb8111e2 # Parent c8bbb32fe124a4e1c6f6b0f66a721c3395e0a539 Be more careful about C integer overflow, #'parse-integer. src/ChangeLog addition: 2015-04-08 Aidan Kehoe * data.c (parse_integer): Fix a bug in my detecting a C overflow here. tests/ChangeLog addition: 2015-04-08 Aidan Kehoe * automated/lisp-tests.el: Add a couple of tests for #'parse-integer to check for a bug just fixed. diff -r c8bbb32fe124 -r c96000075e49 src/ChangeLog --- a/src/ChangeLog Sat Apr 04 13:49:30 2015 +0100 +++ b/src/ChangeLog Wed Apr 08 21:03:18 2015 +0100 @@ -1,3 +1,8 @@ +2015-04-08 Aidan Kehoe + + * data.c (parse_integer): + Fix a bug in my detecting a C overflow here. + 2015-04-01 Aidan Kehoe * process.c (Fgetenv): diff -r c8bbb32fe124 -r c96000075e49 src/data.c --- a/src/data.c Sat Apr 04 13:49:30 2015 +0100 +++ b/src/data.c Wed Apr 08 21:03:18 2015 +0100 @@ -1780,7 +1780,7 @@ onum = num; num *= base; - if (num > fixnum_limit) + if (num > fixnum_limit || num < onum) { goto overflow; } diff -r c8bbb32fe124 -r c96000075e49 tests/ChangeLog --- a/tests/ChangeLog Sat Apr 04 13:49:30 2015 +0100 +++ b/tests/ChangeLog Wed Apr 08 21:03:18 2015 +0100 @@ -1,3 +1,9 @@ +2015-04-08 Aidan Kehoe + + * automated/lisp-tests.el: + Add a couple of tests for #'parse-integer to check for a bug just + fixed. + 2015-03-16 Aidan Kehoe * automated/lisp-tests.el: diff -r c8bbb32fe124 -r c96000075e49 tests/automated/lisp-tests.el --- a/tests/automated/lisp-tests.el Sat Apr 04 13:49:30 2015 +0100 +++ b/tests/automated/lisp-tests.el Wed Apr 08 21:03:18 2015 +0100 @@ -3606,6 +3606,14 @@ (Assert (equal (multiple-value-list (parse-integer "abc" :junk-allowed t)) '(nil 0))) + (Assert (eql (ignore-errors (parse-integer "100000000" + :radix 16)) + (if (featurep 'bignum) (lsh 1 32) nil)) + "checking an overflow bug has been fixed") + (Assert (eql (ignore-errors (parse-integer "-100000000" + :radix 16)) + (if (featurep 'bignum) (- (lsh 1 32) nil)) + "checking an overflow bug has been fixed, negative int") (Check-Error invalid-argument (parse-integer "0123456789" :radix 8)) (Check-Error invalid-argument (parse-integer "abc"))