From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tomas Abrahamsson Newsgroups: gmane.emacs.bugs Subject: bug#794: Artist: patch 2 (of 2): Fix for args-out-of-range error Date: Wed, 27 Aug 2008 14:49:56 +0200 Message-ID: Reply-To: Tomas Abrahamsson , 794@emacsbugs.donarmstrong.com NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1219931016 17956 80.91.229.12 (28 Aug 2008 13:43:36 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 28 Aug 2008 13:43:36 +0000 (UTC) To: bug-gnu-emacs@gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Aug 28 15:44:30 2008 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1KYhkS-0006Cn-VW for geb-bug-gnu-emacs@m.gmane.org; Thu, 28 Aug 2008 15:41:17 +0200 Original-Received: from localhost ([127.0.0.1]:43434 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KYhjU-0004YU-LC for geb-bug-gnu-emacs@m.gmane.org; Thu, 28 Aug 2008 09:40:16 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KYKkJ-0003fr-ME for bug-gnu-emacs@gnu.org; Wed, 27 Aug 2008 09:07:35 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KYKkH-0003eK-G5 for bug-gnu-emacs@gnu.org; Wed, 27 Aug 2008 09:07:34 -0400 Original-Received: from [199.232.76.173] (port=43214 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KYKkH-0003e8-3M for bug-gnu-emacs@gnu.org; Wed, 27 Aug 2008 09:07:33 -0400 Original-Received: from rzlab.ucr.edu ([138.23.92.77]:36301) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1KYKkF-0007Ds-RS for bug-gnu-emacs@gnu.org; Wed, 27 Aug 2008 09:07:32 -0400 Original-Received: from rzlab.ucr.edu (rzlab.ucr.edu [127.0.0.1]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m7RD7TCU030274; Wed, 27 Aug 2008 06:07:30 -0700 Original-Received: (from debbugs@localhost) by rzlab.ucr.edu (8.13.8/8.13.8/Submit) id m7RCt5sd025142; Wed, 27 Aug 2008 05:55:05 -0700 X-Loop: don@donarmstrong.com Resent-From: Tomas Abrahamsson Resent-To: bug-submit-list@donarmstrong.com Resent-CC: Emacs Bugs Resent-Date: Wed, 27 Aug 2008 12:55:04 +0000 Resent-Message-ID: Resent-Sender: don@donarmstrong.com X-Emacs-PR-Message: report 794 X-Emacs-PR-Package: emacs X-Emacs-PR-Keywords: Original-Received: via spool by submit@emacsbugs.donarmstrong.com id=B.121984141124115 (code B ref -1); Wed, 27 Aug 2008 12:55:04 +0000 Original-Received: (at submit) by emacsbugs.donarmstrong.com; 27 Aug 2008 12:50:11 +0000 Original-Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m7RCo5Sk023610 for ; Wed, 27 Aug 2008 05:50:07 -0700 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KYKTM-0006ZB-Q2 for bug-gnu-emacs@gnu.org; Wed, 27 Aug 2008 08:50:04 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KYKTL-0006Yd-1U for bug-gnu-emacs@gnu.org; Wed, 27 Aug 2008 08:50:04 -0400 Original-Received: from [199.232.76.173] (port=35861 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KYKTK-0006YW-Vu for bug-gnu-emacs@gnu.org; Wed, 27 Aug 2008 08:50:03 -0400 Original-Received: from mail.lysator.liu.se ([130.236.254.3]:42917) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1KYKTK-0006Nu-9U for bug-gnu-emacs@gnu.org; Wed, 27 Aug 2008 08:50:02 -0400 Original-Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.lysator.liu.se (Postfix) with ESMTP id 73E64232FBC9 for ; Wed, 27 Aug 2008 14:49:57 +0200 (CEST) Original-Received: from mail.lysator.liu.se ([127.0.0.1]) by localhost (lenin.lysator.liu.se [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 30059-01-8 for ; Wed, 27 Aug 2008 14:49:56 +0200 (CEST) Original-Received: from sellafield.lysator.liu.se (sellafield.lysator.liu.se [130.236.254.103]) by mail.lysator.liu.se (Postfix) with ESMTP id A99C42246D31 for ; Wed, 27 Aug 2008 14:49:56 +0200 (CEST) User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (usg-unix-v) X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at lysator.liu.se X-detected-kernel: by monty-python.gnu.org: Linux 2.6, seldom 2.4 (older, 4) X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 3) Resent-Date: Wed, 27 Aug 2008 09:07:34 -0400 X-Mailman-Approved-At: Thu, 28 Aug 2008 09:39:59 -0400 X-BeenThere: bug-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:19793 Archived-At: Hi, This is the second of two patches for emacs/lisp/textmodes/artist.el. The patches do not depend on each other. They fix different bugs, but they apply to the same file. The patch is against 1.40 of artist.el as checked out from :pserver:anonymous@cvs.savannah.gnu.org:/sources/emacs The patch is written entirely by me. The bug was found by Rub=E9n Berenguel and reported in a private mail to me. As far as I know, the bug has not been reported anywhere else. The bug that this patch fixes is: With e.g. the spray-can mode, using characters whose internal representation was >=3D 256 caused an args-out-of-range error. This is now fixed. Below is a ChangeLog entry and the patch itself. If anythning is unclear or needs more work, please contact me. BRs Tomas The ChangeLog entry: 2008-08-27 Tomas Abrahamsson * textmodes/artist.el (artist-mode-init): Added comment on the setting up of the `artist-replacement-table' array. (artist-get-replacement-char): New. (artist-get-char-at-xy-conv, artist-replace-char) (artist-replace-chars, artist-replace-string): Use it instead of accessing `artist-replacement-table' directly. Reported by Rub=E9n Berenguel . The patch: Index: artist.el =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /sources/emacs/emacs/lisp/textmodes/artist.el,v retrieving revision 1.40 diff -u -r1.40 artist.el --- artist.el 12 Jun 2008 03:56:20 -0000 1.40 +++ artist.el 26 Aug 2008 23:34:09 -0000 @@ -1375,6 +1375,9 @@ ;; Init and exit (defun artist-mode-init () "Init Artist mode. This will call the hook `artist-mode-init-hook'." + ;; Set up a conversion table for mapping tabs and new-lines to spaces. + ;; the last case, 0, is for the last position in buffer/region, where + ;; the `following-char' function returns 0. (let ((i 0)) (while (< i 256) (aset artist-replacement-table i i) @@ -1382,6 +1385,7 @@ (aset artist-replacement-table ?\n ?\s) (aset artist-replacement-table ?\t ?\s) (aset artist-replacement-table 0 ?\s) + ;; More setup (make-local-variable 'artist-key-is-drawing) (make-local-variable 'artist-key-endpoint1) (make-local-variable 'artist-key-poly-point-list) @@ -1944,10 +1948,21 @@ (following-char)) =20 =20 +(defsubst artist-get-replacement-char (c) + "Retrieve a replacement for character C from `artist-replacement-table= '. +The replacement is used to convert tabs and new-lines to spaces." + ;; Characters may be outside the range of the `artist-replacement-tabl= e', + ;; for example if they are unicode code points >=3D 256. + ;; Check so we don't attempt to access the array out of its bounds, + ;; assuming no such character needs to be replaced. + (if (< c (length artist-replacement-table)) + (aref artist-replacement-table c) + c)) + (defun artist-get-char-at-xy-conv (x y) "Retrieve the character at X, Y, converting tabs and new-lines to spac= es." (save-excursion - (aref artist-replacement-table (artist-get-char-at-xy x y)))) + (artist-get-replacement-char (artist-get-char-at-xy x y)))) =20 =20 (defun artist-replace-char (new-char) @@ -1963,12 +1978,12 @@ (artist-move-to-xy (1+ (artist-current-column)) (artist-current-line)) (delete-char -1) - (insert (aref artist-replacement-table new-char))) + (insert (artist-get-replacement-char new-char))) ;; In emacs-19, the self-insert-command works better and faster (let ((overwrite-mode 'overwrite-mode-textual) (fill-column 32765) ; Large :-) (blink-matching-paren nil)) - (setq last-command-event (aref artist-replacement-table new-char)) + (setq last-command-event (artist-get-replacement-char new-char)) (self-insert-command 1)))) =20 (defun artist-replace-chars (new-char count) @@ -1980,7 +1995,7 @@ ;; The self-insert-command doesn't care about the overwrite-mode, ;; so the insertion is done in the same way as in picture mode. ;; This seems to be a little bit slower. - (let* ((replaced-c (aref artist-replacement-table new-char)) + (let* ((replaced-c (artist-get-replacement-char new-char)) (replaced-s (make-string count replaced-c))) (artist-move-to-xy (+ (artist-current-column) count) (artist-current-line)) @@ -1990,7 +2005,7 @@ (let ((overwrite-mode 'overwrite-mode-textual) (fill-column 32765) ; Large :-) (blink-matching-paren nil)) - (setq last-command-event (aref artist-replacement-table new-char)) + (setq last-command-event (artist-get-replacement-char new-char)) (self-insert-command count)))) =20 (defsubst artist-replace-string (string &optional see-thru) @@ -2003,7 +2018,7 @@ (blink-matching-paren nil)) (while char-list (let ((c (car char-list))) - (if (and see-thru (=3D (aref artist-replacement-table c) ?\s)) + (if (and see-thru (=3D (artist-get-replacement-char c) ?\s)) (artist-move-to-xy (1+ (artist-current-column)) (artist-current-line)) (artist-replace-char c)))