GNU bug report logs - #29799
24.5; cl-loop guard clause missing

Previous Next

Package: emacs;

Reported by: Tino Calancha <tino.calancha <at> gmail.com>

Date: Thu, 21 Dec 2017 09:39:02 UTC

Severity: normal

Tags: fixed

Found in version 24.5

Fixed in version 28.1

Done: Noam Postavsky <npostavs <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Tino Calancha <tino.calancha <at> gmail.com>
Subject: bug#29799: closed (Re: bug#29799: 24.5; cl-loop guard clause missing)
Date: Mon, 08 Jan 2018 10:21:02 +0000
[Message part 1 (text/plain, inline)]
Your bug report

#29799: 24.5; cl-loop guard clause missing

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to 29799 <at> debbugs.gnu.org.

-- 
29799: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=29799
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: Tino Calancha <tino.calancha <at> gmail.com>
To: 29799-done <at> debbugs.gnu.org
Subject: Re: bug#29799: 24.5; cl-loop guard clause missing
Date: Mon, 08 Jan 2018 19:20:35 +0900
Noam Postavsky <npostavs <at> users.sourceforge.net> writes:

> Tino Calancha <tino.calancha <at> gmail.com> writes:
>
>>     Fix #Bug#29799
>>     
>>     * lisp/emacs-lisp/cl-macs.el (cl--loop-guard-cond): New variable.
>>     (cl--parse-loop-clause): Set it non-nil if the loop contains
>>     a for/as clause.
>>     (cl-loop): After update the loop variable, update other variables
>>     only if cl--loop-guard-cond is non-nil.
>>     
>>     * test/lisp/emacs-lisp/cl-macs-tests.el (cl-macs-loop-for-as-equals-and):
>>     New test.
>
> Looks good, but please add some more info to the summary line.
Thank you very much.
Extended the commit message with more detailed explanations.

Fixed in master branch as commit 'cl-loop: Add missing guard condition'
(a0365437c9ee308ad7978e436631020f513b25e7).

[Message part 3 (message/rfc822, inline)]
From: Tino Calancha <tino.calancha <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 24.5; cl-loop guard clause missing
Date: Thu, 21 Dec 2017 18:38:20 +0900
X-Debbugs-CC: monnier <at> iro.umontreal.ca,npostavs <at> gmail.com

Consider the following snippet code:

--8<-----------------------------cut here---------------start------------->8---
(require 'cl-lib)
(let* ((size 7)
       (arr (make-vector size 0)))
  (cl-loop for k below size
           for x = (* 2 k) and y = (1+ (elt arr k))
           collect (list k x y)))
--8<-----------------------------cut here---------------end--------------->8---

When you execute the form above it fails because
the loop overrun `arr'.

The equivalent code in CL works:
--8<-----------------------------cut here---------------start------------->8---
(let* ((size 7)
       (arr (make-array size :initial-element 0)))
  (loop :for k :below size
           :for x = (* 2 k) :and y = (1+ (elt arr k))
           :collect (list k x y)))
--8<-----------------------------cut here---------------end--------------->8---

* The expansion of `loop' in CL checks the condition
  (>= k 7)
  right before update the internal variables (`x' and `y').

* The expansion of `cl-loop' instead, doesn't check the condition
  before update the vars  =>  in the code above we overrun `arr'.


In GNU Emacs 24.5.1 (x86_64-pc-linux-gnu, GTK+ Version 3.22.11)
 of 2017-09-12 on hullmann, modified by Debian
Windowing system distributor `The X.Org Foundation', version 11.0.11902000
System Description:	Debian GNU/Linux 9.3 (stretch)



This bug report was last modified 5 years and 19 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.