unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Calc; Fix c type hex parse on `quick-calc'
@ 2017-11-09 18:31 OGAWA Hirofumi
  2017-11-18 10:34 ` Eli Zaretskii
  0 siblings, 1 reply; 2+ messages in thread
From: OGAWA Hirofumi @ 2017-11-09 18:31 UTC (permalink / raw)
  To: emacs-devel

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 <hirofumi@mail.parknet.co.jp>



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Calc; Fix c type hex parse on `quick-calc'
  2017-11-09 18:31 Calc; Fix c type hex parse on `quick-calc' OGAWA Hirofumi
@ 2017-11-18 10:34 ` Eli Zaretskii
  0 siblings, 0 replies; 2+ messages in thread
From: Eli Zaretskii @ 2017-11-18 10:34 UTC (permalink / raw)
  To: OGAWA Hirofumi; +Cc: emacs-devel

> From: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
> Date: Fri, 10 Nov 2017 03:31:00 +0900
> 
> 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.

Thanks, I installed your changes.



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-11-18 10:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-11-09 18:31 Calc; Fix c type hex parse on `quick-calc' OGAWA Hirofumi
2017-11-18 10:34 ` Eli Zaretskii

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).