[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Calc; Fix c type hex parse on `quick-calc'
From: |
OGAWA Hirofumi |
Subject: |
Calc; Fix c type hex parse on `quick-calc' |
Date: |
Fri, 10 Nov 2017 03:31:00 +0900 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) |
This bug is reproducible with following commands.
$ emacs -Q
M-: (setq calc-language 'c)
M-x quick-calc
Quick calc: 1024 + 0x20
Result: 32 => 32 (0x20, 040, 2#100000, " ")
Like above, the result is wrong (expected result is following).
Result: 1024 + 32 => 1056 (0x420, 02040, 2#10000100000)
The bug is in `math-read-token'.
(or (and (memq calc-language calc-lang-c-type-hex)
(string-match "0[xX][0-9a-fA-F]+" math-exp-str math-exp-pos))
We want to get "1024" as token at first, but the above part matches at
"0x20" part of expr, and skips "1024 + ".
In this context, we want to check if current token is matching to
c-type hex or not. So we should check regex is matched at
math-exp-pos. This patch fixes this bug.
Emacs : GNU Emacs 27.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.22.24)
of 2017-11-10
Package: Calc
---
lisp/calc/calc-aent.el | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff -puN lisp/calc/calc-aent.el~calc-c-lang-fix lisp/calc/calc-aent.el
--- emacs/lisp/calc/calc-aent.el~calc-c-lang-fix 2017-11-10
03:10:09.780135078 +0900
+++ emacs-hirofumi/lisp/calc/calc-aent.el 2017-11-10 03:10:42.294060877
+0900
@@ -728,7 +728,8 @@ in Calc algebraic input.")
math-exp-str (1- math-exp-pos))
(1- math-exp-pos))))))
(or (and (memq calc-language calc-lang-c-type-hex)
- (string-match "0[xX][0-9a-fA-F]+" math-exp-str
math-exp-pos))
+ (eq (string-match "0[xX][0-9a-fA-F]+" math-exp-str
math-exp-pos)
+ math-exp-pos))
(string-match "_?\\([0-9]+.?0*@ *\\)?\\([0-9]+.?0*'
*\\)?\\(0*\\([2-9]\\|1[0-4]\\)\\(#[#]?\\|\\^\\^\\)[0-9a-dA-D.]+[eE][-+_]?[0-9]+\\|0*\\([2-9]\\|[0-2][0-9]\\|3[0-6]\\)\\(#[#]?\\|\\^\\^\\)[0-9a-zA-Zα-ωΑ-Ω:.]+\\|[0-9]+:[0-9:]+\\|[0-9.]+\\([eE][-+_]?[0-9]+\\)?\"?\\)?"
math-exp-str math-exp-pos))
(setq math-exp-token 'number
_
--
OGAWA Hirofumi <address@hidden>
- Calc; Fix c type hex parse on `quick-calc',
OGAWA Hirofumi <=