all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Mattias Engdegård" <mattiase@acm.org>
To: Narendra Joshi <narendraj9@gmail.com>
Cc: 40155@debbugs.gnu.org
Subject: bug#40155: 27.0.90; `math-truc' called with `nil' during `calc-graph-fast' call
Date: Fri, 27 Mar 2020 18:37:17 +0100	[thread overview]
Message-ID: <F33F5D12-DC0C-410D-B511-401BF43BE6AA@acm.org> (raw)
In-Reply-To: <87pnd6bx0k.fsf@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 738 bytes --]

Thanks for the report. Explanation:

The graph code does

(and (Math-num-integerp lstyle) (math-trunc lstyle))

but Math-num-integerp returns true for nil, and math-trunc returns the argument if it satisfies Math-integerp, which used to return true for nil as well. Thus, the expression above 'works' (ie, returns nil) when lstyle is nil as well.

However, Math-integerp was changed in Emacs 27 to use native bignums, and no longer returns true for nil, resulting in the error. Changing Math-num-integerp to return false for nil would make the code work again, this time in the way originally intended.

Would you try this patch? (Please try various other operations as well, in case the change had unintended consequences.)


[-- Attachment #2: 0001-Calc-don-t-treat-nil-as-an-integer-bug-40155.patch --]
[-- Type: application/octet-stream, Size: 1965 bytes --]

From c2b8ce4439935e2e158d4357d234135a251c5767 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mattias=20Engdeg=C3=A5rd?= <mattiase@acm.org>
Date: Fri, 27 Mar 2020 18:11:18 +0100
Subject: [PATCH] Calc: don't treat nil as an integer (bug#40155)

Make Math-num-integerp return false for nil, following Math-integerp
which was changed in the bignum reform.  This fixes a crash in
calc-graph-fast.

Reported by Narendra Joshi.

* lisp/calc/calc-macs.el (Math-num-integerp): Not true for nil.
* test/lisp/calc/calc-tests.el (calc-Math-integerp): New tests.
---
 lisp/calc/calc-macs.el       |  5 +++--
 test/lisp/calc/calc-tests.el | 11 +++++++++++
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/lisp/calc/calc-macs.el b/lisp/calc/calc-macs.el
index e73d108e6d..257d369b87 100644
--- a/lisp/calc/calc-macs.el
+++ b/lisp/calc/calc-macs.el
@@ -161,8 +161,9 @@ Math-primp
 		      hms date mod var))))
 
 (defsubst Math-num-integerp (a)
-  (or (not (consp a))
-      (and (eq (car a) 'float)
+  (or (integerp a)
+      (and (consp a)
+           (eq (car a) 'float)
 	   (>= (nth 2 a) 0))))
 
 (defsubst Math-equal-int (a b)
diff --git a/test/lisp/calc/calc-tests.el b/test/lisp/calc/calc-tests.el
index 784b404898..8fffb7c14b 100644
--- a/test/lisp/calc/calc-tests.el
+++ b/test/lisp/calc/calc-tests.el
@@ -334,6 +334,17 @@ calc-poly-div
         (should (equal tos '(- (* 2 (var x var-x)) 4)))
         (should (equal trail "pdiv 2 * x - 4\nprem 8 * x + 1\n"))))))
 
+(ert-deftest calc-Math-integerp ()
+  (should (Math-integerp -7))
+  (should (Math-integerp (ash 1 65)))
+  (should-not (Math-integerp '(float 1 0)))
+  (should-not (Math-integerp nil))
+
+  (should (Math-num-integerp -7))
+  (should (Math-num-integerp (ash 1 65)))
+  (should (Math-num-integerp '(float 1 0)))
+  (should-not (Math-integerp nil)))
+
 (provide 'calc-tests)
 ;;; calc-tests.el ends here
 
-- 
2.21.1 (Apple Git-122.3)


  reply	other threads:[~2020-03-27 17:37 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-20 20:18 bug#40155: 27.0.90; `math-truc' called with `nil' during `calc-graph-fast' call Narendra Joshi
2020-03-27 17:37 ` Mattias Engdegård [this message]
2020-03-27 20:54   ` Narendra Joshi
2020-03-28 13:35     ` Mattias Engdegård
2020-03-28 13:58       ` Narendra Joshi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=F33F5D12-DC0C-410D-B511-401BF43BE6AA@acm.org \
    --to=mattiase@acm.org \
    --cc=40155@debbugs.gnu.org \
    --cc=narendraj9@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.