diff options
| author | Mattias EngdegÄrd | 2019-07-10 19:24:58 +0200 |
|---|---|---|
| committer | Mattias EngdegÄrd | 2019-09-23 15:06:53 +0200 |
| commit | bd0f173199c112b2b146e727f80e973e7fc12143 (patch) | |
| tree | 36e80c5d5b1bba4ee98e6a5ed085fdbe7de3bfa1 /lisp | |
| parent | 73e1727c405214086bb3a0647c91855e1b0853c2 (diff) | |
| download | emacs-bd0f173199c112b2b146e727f80e973e7fc12143.tar.gz emacs-bd0f173199c112b2b146e727f80e973e7fc12143.zip | |
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.el | 18 |
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 @@ | |||
| 847 | (and (eq calc-angle-mode 'rad) | 847 | (and (eq calc-angle-mode 'rad) |
| 848 | (let ((n (math-linear-in (nth 1 math-simplify-expr) '(var pi var-pi)))) | 848 | (let ((n (math-linear-in (nth 1 math-simplify-expr) '(var pi var-pi)))) |
| 849 | (and n | 849 | (and n |
| 850 | (math-div 1 (math-known-sin (car n) (nth 1 n) 120 300))))) | 850 | (let ((s (math-known-sin (car n) (nth 1 n) 120 300))) |
| 851 | (and s (math-div 1 s)))))) | ||
| 851 | (and (eq calc-angle-mode 'deg) | 852 | (and (eq calc-angle-mode 'deg) |
| 852 | (let ((n (math-integer-plus (nth 1 math-simplify-expr)))) | 853 | (let ((n (math-integer-plus (nth 1 math-simplify-expr)))) |
| 853 | (and n | 854 | (and n |
| 854 | (math-div 1 (math-known-sin (car n) (nth 1 n) '(frac 2 3) 300))))) | 855 | (let ((s (math-known-sin (car n) (nth 1 n) '(frac 2 3) 300))) |
| 856 | (and s (math-div 1 s)))))) | ||
| 855 | (and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arcsin) | 857 | (and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arcsin) |
| 856 | (math-div | 858 | (math-div |
| 857 | 1 | 859 | 1 |
| @@ -872,11 +874,13 @@ | |||
| 872 | (and (eq calc-angle-mode 'rad) | 874 | (and (eq calc-angle-mode 'rad) |
| 873 | (let ((n (math-linear-in (nth 1 math-simplify-expr) '(var pi var-pi)))) | 875 | (let ((n (math-linear-in (nth 1 math-simplify-expr) '(var pi var-pi)))) |
| 874 | (and n | 876 | (and n |
| 875 | (math-div 1 (math-known-sin (car n) (nth 1 n) 120 0))))) | 877 | (let ((s (math-known-sin (car n) (nth 1 n) 120 0))) |
| 878 | (and s (math-div 1 s)))))) | ||
| 876 | (and (eq calc-angle-mode 'deg) | 879 | (and (eq calc-angle-mode 'deg) |
| 877 | (let ((n (math-integer-plus (nth 1 math-simplify-expr)))) | 880 | (let ((n (math-integer-plus (nth 1 math-simplify-expr)))) |
| 878 | (and n | 881 | (and n |
| 879 | (math-div 1 (math-known-sin (car n) (nth 1 n) '(frac 2 3) 0))))) | 882 | (let ((s (math-known-sin (car n) (nth 1 n) '(frac 2 3) 0))) |
| 883 | (and s (math-div 1 s)))))) | ||
| 880 | (and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arcsin) | 884 | (and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arcsin) |
| 881 | (math-div 1 (nth 1 (nth 1 math-simplify-expr)))) | 885 | (math-div 1 (nth 1 (nth 1 math-simplify-expr)))) |
| 882 | (and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arccos) | 886 | (and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arccos) |
| @@ -977,11 +981,13 @@ | |||
| 977 | (and (eq calc-angle-mode 'rad) | 981 | (and (eq calc-angle-mode 'rad) |
| 978 | (let ((n (math-linear-in (nth 1 math-simplify-expr) '(var pi var-pi)))) | 982 | (let ((n (math-linear-in (nth 1 math-simplify-expr) '(var pi var-pi)))) |
| 979 | (and n | 983 | (and n |
| 980 | (math-div 1 (math-known-tan (car n) (nth 1 n) 120))))) | 984 | (let ((tn (math-known-tan (car n) (nth 1 n) 120))) |
| 985 | (and tn (math-div 1 tn)))))) | ||
| 981 | (and (eq calc-angle-mode 'deg) | 986 | (and (eq calc-angle-mode 'deg) |
| 982 | (let ((n (math-integer-plus (nth 1 math-simplify-expr)))) | 987 | (let ((n (math-integer-plus (nth 1 math-simplify-expr)))) |
| 983 | (and n | 988 | (and n |
| 984 | (math-div 1 (math-known-tan (car n) (nth 1 n) '(frac 2 3)))))) | 989 | (let ((tn (math-known-tan (car n) (nth 1 n) '(frac 2 3)))) |
| 990 | (and tn (math-div 1 tn)))))) | ||
| 985 | (and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arcsin) | 991 | (and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arcsin) |
| 986 | (math-div (list 'calcFunc-sqrt | 992 | (math-div (list 'calcFunc-sqrt |
| 987 | (math-sub 1 (math-sqr (nth 1 (nth 1 math-simplify-expr))))) | 993 | (math-sub 1 (math-sqr (nth 1 (nth 1 math-simplify-expr))))) |