From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: "Basil L. Contovounesios" Newsgroups: gmane.emacs.bugs Subject: bug#35285: 27.0.50; Bug in image--set-property; setf Date: Wed, 17 Apr 2019 14:36:20 +0100 Message-ID: <87r2a092jv.fsf@tcd.ie> References: <87k1fvd0cw.fsf@tullinup.koldfront.dk> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="76445"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: 35285@debbugs.gnu.org To: Adam =?UTF-8?Q?Sj=C3=B8gren?= Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Apr 17 15:37:28 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hGkki-000Jfq-Ia for geb-bug-gnu-emacs@m.gmane.org; Wed, 17 Apr 2019 15:37:28 +0200 Original-Received: from localhost ([127.0.0.1]:52680 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hGkkh-0002f7-Hm for geb-bug-gnu-emacs@m.gmane.org; Wed, 17 Apr 2019 09:37:27 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:59246) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hGkkK-0002S2-CN for bug-gnu-emacs@gnu.org; Wed, 17 Apr 2019 09:37:05 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hGkkJ-0007kI-2e for bug-gnu-emacs@gnu.org; Wed, 17 Apr 2019 09:37:04 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:54413) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hGkkI-0007jG-1w for bug-gnu-emacs@gnu.org; Wed, 17 Apr 2019 09:37:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hGkkH-0005RQ-Pv for bug-gnu-emacs@gnu.org; Wed, 17 Apr 2019 09:37:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: "Basil L. Contovounesios" Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 17 Apr 2019 13:37:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 35285 X-GNU-PR-Package: emacs Original-Received: via spool by 35285-submit@debbugs.gnu.org id=B35285.155550819420875 (code B ref 35285); Wed, 17 Apr 2019 13:37:01 +0000 Original-Received: (at 35285) by debbugs.gnu.org; 17 Apr 2019 13:36:34 +0000 Original-Received: from localhost ([127.0.0.1]:39724 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hGkjp-0005QX-NE for submit@debbugs.gnu.org; Wed, 17 Apr 2019 09:36:34 -0400 Original-Received: from mail-ed1-f48.google.com ([209.85.208.48]:46787) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hGkjm-0005Q8-Nt for 35285@debbugs.gnu.org; Wed, 17 Apr 2019 09:36:31 -0400 Original-Received: by mail-ed1-f48.google.com with SMTP id d1so20980062edd.13 for <35285@debbugs.gnu.org>; Wed, 17 Apr 2019 06:36:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tcd-ie.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=fwmZ1WT5wU1ipqrR2HmddudaHsPmXef5DPo9sowOUQ8=; b=abqaD2x1qhmmZOE+czTCsvdBWDqjZYCjNWOZWteaFTD6LonqaKYxWs49eH+zarFHbg N9uk3MX3lw7gU4QwfaWvWBCBxExQDu4fdLOQWj5NnejRjd0YBfJQ4S3tGZb3xMIMi0T9 w8ciBb+r0DSqoIeFqYv5rY7HCQA/AoIGX17lxkYX6MYE0ei9GskpjmJIiwj8u05kRJTw 07egdrORhk82Kaa3qe40ZGPI+8zYOrbfzNb6OMb8xiqDUFAv7XmWpCml90cCw26T1blN /AQv2TncyTF9fkpyO469H3BymgbTDy+S7mHu/oSFX1QWWyK5g7DFjgaKCSpN6pPirA28 lG8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=fwmZ1WT5wU1ipqrR2HmddudaHsPmXef5DPo9sowOUQ8=; b=HTTJSXgzNf6Atib7NoQvZaelkxgz1vhJvOp7Dk7pxo5VFacTeyG4WiRRs11hn4CKi/ zLraQBV99/8wBsHq7iOn4YdAJNhKs0VQ6K80GqgxbAx93hwxJos6BO6tfACdreUDX92F FjeaHdrT799avjTGPGIhJ3NjEODR2CSPKNuqwjFUQ9fr+EsnLGNMWK/8N8jHdGPxxhVB 7LQu3AW3on1BTIzH8jVbiOMz0Lp9ACuC7ykogA/bhNcasQMwcTbTl+LFqElfkqTRlQaC 1XcmR2s7jrz74gTuvnwkGTvvSpg+H9vraHvmSLS4m/eoIl5oC7zERs9S5sxAd5c8UwxT omTQ== X-Gm-Message-State: APjAAAXqU9c8FstPJL6Iq98UkY8NDye9k0/FsjCMGdsMMJh7QQWDKmr+ s6fOfSbJ7QaaGN1vfqJi8cKcig== X-Google-Smtp-Source: APXvYqyh2RWeEYSofBwcuBJ/xLVNFIAbFjIcrjRr67U7LSYiYi69TuhzZ4AlLbEWCs2QTsxWZGYf9g== X-Received: by 2002:a17:906:b6c8:: with SMTP id ec8mr46913061ejb.89.1555508183706; Wed, 17 Apr 2019 06:36:23 -0700 (PDT) Original-Received: from localhost ([86.43.102.231]) by smtp.gmail.com with ESMTPSA id d33sm7569113edc.45.2019.04.17.06.36.21 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 17 Apr 2019 06:36:22 -0700 (PDT) In-Reply-To: <87k1fvd0cw.fsf@tullinup.koldfront.dk> ("Adam =?UTF-8?Q?Sj=C3=B8gren?="'s message of "Mon, 15 Apr 2019 12:33:19 +0200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:157765 Archived-At: --=-=-= Content-Type: text/plain tags 35285 patch quit --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Fix-off-by-one-link-error-in-image-set-property.patch >From b611408fe29e3e15e002d799dbaf98f813aa7530 Mon Sep 17 00:00:00 2001 From: "Basil L. Contovounesios" Date: Wed, 17 Apr 2019 14:24:31 +0100 Subject: [PATCH] Fix off-by-one-link error in image--set-property * lisp/image.el (image--set-property): Ensure new value is set even in the unlikely case that the plist is empty. Fix off-by-one-link error when deleting a property. (bug#35285) * test/lisp/image-tests.el: New file. (image--set-property): New test. --- lisp/image.el | 4 ++-- test/lisp/image-tests.el | 45 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 test/lisp/image-tests.el diff --git a/lisp/image.el b/lisp/image.el index 6da3a0b6cd..ba87d7f785 100644 --- a/lisp/image.el +++ b/lisp/image.el @@ -454,10 +454,10 @@ image--set-property ;; plist. Decouple plist entries where the key matches ;; the property. (if (eq (cadr image) property) - (setcdr image (cddr image)) + (setcdr image (cdddr image)) (setq image (cddr image)))) ;; Just enter the new value. - (plist-put (cdr image) property value)) + (setcdr image (plist-put (cdr image) property value))) value) (defun image-property (image property) diff --git a/test/lisp/image-tests.el b/test/lisp/image-tests.el new file mode 100644 index 0000000000..89b926e629 --- /dev/null +++ b/test/lisp/image-tests.el @@ -0,0 +1,45 @@ +;;; image-tests.el --- tests for image.el -*- lexical-binding: t -*- + +;; Copyright (C) 2019 Free Software Foundation, Inc. + +;; This file is part of GNU Emacs. + +;; GNU Emacs is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; GNU Emacs is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs. If not, see . + +;;; Code: + +(require 'ert) +(require 'image) + +(ert-deftest image--set-property () + "Test `image--set-property' behavior." + (let ((image (list 'image))) + ;; Add properties. + (setf (image-property image :scale) 1) + (should (equal image '(image :scale 1))) + (setf (image-property image :width) 8) + (should (equal image '(image :scale 1 :width 8))) + (setf (image-property image :height) 16) + (should (equal image '(image :scale 1 :width 8 :height 16))) + ;; Delete properties. + (setf (image-property image :type) nil) + (should (equal image '(image :scale 1 :width 8 :height 16))) + (setf (image-property image :scale) nil) + (should (equal image '(image :width 8 :height 16))) + (setf (image-property image :height) nil) + (should (equal image '(image :width 8))) + (setf (image-property image :width) nil) + (should (equal image '(image))))) + +;;; image-tests.el ends here -- 2.20.1 --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Adam Sj=C3=B8gren writes: > Xu Chunyang analysed the problem with setf I presented on > emacs.stackexchange.com=C2=B9 as so: > > There is a bug in image--set-property, (setcdr image (cddr image)) > should be (setcdr image (cdddr image)), i.e., change cddr into cdddr I agree that this is the problem, and the attached patch should fix that. Eli, should this go to emacs-26 or master? Thanks, --=20 Basil --=-=-=--