summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authorMattias EngdegÄrd <mattiase@acm.org>2019-07-10 19:24:58 +0200
committerMattias EngdegÄrd <mattiase@acm.org>2019-09-23 15:06:53 +0200
commitbd0f173199c112b2b146e727f80e973e7fc12143 (patch)
tree36e80c5d5b1bba4ee98e6a5ed085fdbe7de3bfa1 /lisp
parent73e1727c405214086bb3a0647c91855e1b0853c2 (diff)
downloademacs-bd0f173199c112b2b146e727f80e973e7fc12143.tar.gz
Fix trig simplification crash (bug#33052)
* lisp/calc/calc-alg.el (calcFunc-sec, calcFunc-csc, calcFunc-cot): Check that `math-known-sin' and `math-known-tan' succeeded before using their value in arithmetic. * test/lisp/calc/calc-tests.el (calc-test-trig): Add regression tests. Backport from master.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/calc/calc-alg.el18
1 files changed, 12 insertions, 6 deletions
diff --git a/lisp/calc/calc-alg.el b/lisp/calc/calc-alg.el
index 8e3476d191e..b41749ca775 100644
--- a/lisp/calc/calc-alg.el
+++ b/lisp/calc/calc-alg.el
@@ -847,11 +847,13 @@
(and (eq calc-angle-mode 'rad)
(let ((n (math-linear-in (nth 1 math-simplify-expr) '(var pi var-pi))))
(and n
- (math-div 1 (math-known-sin (car n) (nth 1 n) 120 300)))))
+ (let ((s (math-known-sin (car n) (nth 1 n) 120 300)))
+ (and s (math-div 1 s))))))
(and (eq calc-angle-mode 'deg)
(let ((n (math-integer-plus (nth 1 math-simplify-expr))))
(and n
- (math-div 1 (math-known-sin (car n) (nth 1 n) '(frac 2 3) 300)))))
+ (let ((s (math-known-sin (car n) (nth 1 n) '(frac 2 3) 300)))
+ (and s (math-div 1 s))))))
(and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arcsin)
(math-div
1
@@ -872,11 +874,13 @@
(and (eq calc-angle-mode 'rad)
(let ((n (math-linear-in (nth 1 math-simplify-expr) '(var pi var-pi))))
(and n
- (math-div 1 (math-known-sin (car n) (nth 1 n) 120 0)))))
+ (let ((s (math-known-sin (car n) (nth 1 n) 120 0)))
+ (and s (math-div 1 s))))))
(and (eq calc-angle-mode 'deg)
(let ((n (math-integer-plus (nth 1 math-simplify-expr))))
(and n
- (math-div 1 (math-known-sin (car n) (nth 1 n) '(frac 2 3) 0)))))
+ (let ((s (math-known-sin (car n) (nth 1 n) '(frac 2 3) 0)))
+ (and s (math-div 1 s))))))
(and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arcsin)
(math-div 1 (nth 1 (nth 1 math-simplify-expr))))
(and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arccos)
@@ -977,11 +981,13 @@
(and (eq calc-angle-mode 'rad)
(let ((n (math-linear-in (nth 1 math-simplify-expr) '(var pi var-pi))))
(and n
- (math-div 1 (math-known-tan (car n) (nth 1 n) 120)))))
+ (let ((tn (math-known-tan (car n) (nth 1 n) 120)))
+ (and tn (math-div 1 tn))))))
(and (eq calc-angle-mode 'deg)
(let ((n (math-integer-plus (nth 1 math-simplify-expr))))
(and n
- (math-div 1 (math-known-tan (car n) (nth 1 n) '(frac 2 3))))))
+ (let ((tn (math-known-tan (car n) (nth 1 n) '(frac 2 3))))
+ (and tn (math-div 1 tn))))))
(and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arcsin)
(math-div (list 'calcFunc-sqrt
(math-sub 1 (math-sqr (nth 1 (nth 1 math-simplify-expr)))))