From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: OGAWA Hirofumi Newsgroups: gmane.emacs.devel Subject: Calc; Fix c type hex parse on `quick-calc' Date: Fri, 10 Nov 2017 03:31:00 +0900 Message-ID: <87bmkbjod7.fsf@mail.parknet.co.jp> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-2022-jp X-Trace: blaine.gmane.org 1510259330 23782 195.159.176.226 (9 Nov 2017 20:28:50 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 9 Nov 2017 20:28:50 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Nov 09 21:28:46 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eCtRN-0005xL-1f for ged-emacs-devel@m.gmane.org; Thu, 09 Nov 2017 21:28:45 +0100 Original-Received: from localhost ([::1]:38653 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eCtRU-00019B-FG for ged-emacs-devel@m.gmane.org; Thu, 09 Nov 2017 15:28:52 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36640) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eCrbZ-0007cj-3t for emacs-devel@gnu.org; Thu, 09 Nov 2017 13:31:10 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eCrbV-0004Dd-Vl for emacs-devel@gnu.org; Thu, 09 Nov 2017 13:31:09 -0500 Original-Received: from mail.parknet.co.jp ([210.171.160.6]:47341) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eCrbV-0004CE-Lw for emacs-devel@gnu.org; Thu, 09 Nov 2017 13:31:05 -0500 Original-Received: from ibmpc.myhome.or.jp (server.parknet.ne.jp [210.171.168.39]) by mail.parknet.co.jp (Postfix) with ESMTP id 3CF911E004B for ; Fri, 10 Nov 2017 03:31:02 +0900 (JST) Original-Received: from devron.myhome.or.jp (root@devron.myhome.or.jp [192.168.0.3]) by ibmpc.myhome.or.jp (8.15.2/8.15.2/Debian-9) with ESMTPS id vA9IV0eN008465 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 10 Nov 2017 03:31:02 +0900 Original-Received: from devron.myhome.or.jp (hirofumi@localhost [127.0.0.1]) by devron.myhome.or.jp (8.15.2/8.15.2/Debian-9) with ESMTPS id vA9IV0Tg003611 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 10 Nov 2017 03:31:00 +0900 Original-Received: (from hirofumi@localhost) by devron.myhome.or.jp (8.15.2/8.15.2/Submit) id vA9IV0Pg003609; Fri, 10 Nov 2017 03:31:00 +0900 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] [fuzzy] X-Received-From: 210.171.160.6 X-Mailman-Approved-At: Thu, 09 Nov 2017 15:28:05 -0500 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:220007 Archived-At: 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