GNU bug report logs - #63807
bug in compose-gstring-for-terminal?

Previous Next

Package: emacs;

Reported by: Mattias Engdegård <mattias.engdegard <at> gmail.com>

Date: Tue, 30 May 2023 20:37:01 UTC

Severity: normal

Done: Mattias Engdegård <mattias.engdegard <at> gmail.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 63807 in the body.
You can then email your comments to 63807 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#63807; Package emacs. (Tue, 30 May 2023 20:37:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Mattias Engdegård <mattias.engdegard <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Tue, 30 May 2023 20:37:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Mattias Engdegård <mattias.engdegard <at> gmail.com>
To: Emacs Bug Report <bug-gnu-emacs <at> gnu.org>
Subject: bug in compose-gstring-for-terminal?
Date: Tue, 30 May 2023 22:36:18 +0200
There is what appears to be a little code accident in compose-gstring-for-terminal, at composite.el:821:

	      (setq i (+ 2)))

but someone who knows the character composition code better should have a look. The remedy seems obvious, though.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#63807; Package emacs. (Wed, 31 May 2023 13:02:01 GMT) Full text and rfc822 format available.

Message #8 received at 63807 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Mattias Engdegård <mattias.engdegard <at> gmail.com>
Cc: 63807 <at> debbugs.gnu.org
Subject: Re: bug#63807: bug in compose-gstring-for-terminal?
Date: Wed, 31 May 2023 16:02:31 +0300
> From: Mattias Engdegård <mattias.engdegard <at> gmail.com>
> Date: Tue, 30 May 2023 22:36:18 +0200
> 
> There is what appears to be a little code accident in compose-gstring-for-terminal, at composite.el:821:
> 
> 	      (setq i (+ 2)))
> 
> but someone who knows the character composition code better should have a look. The remedy seems obvious, though.

Why do you think it could be a bug?  Setting i to 2 is correct there,
AFAICT.  If you want to remove the redundant '+', be my guest, but I
very much hope the new warnings on master will not suddenly start warn
about such code: it's completely legit.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#63807; Package emacs. (Wed, 31 May 2023 13:50:02 GMT) Full text and rfc822 format available.

Message #11 received at 63807 <at> debbugs.gnu.org (full text, mbox):

From: Mattias Engdegård <mattias.engdegard <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 63807 <at> debbugs.gnu.org
Subject: Re: bug#63807: bug in compose-gstring-for-terminal?
Date: Wed, 31 May 2023 15:49:23 +0200
31 maj 2023 kl. 15.02 skrev Eli Zaretskii <eliz <at> gnu.org>:

> Setting i to 2 is correct there

Would you explain why to someone who doesn't know how this is supposed to work?
There may be external invariants rescuing the mistake from having serious consequences so that the code is correct in a narrow sense but relying that is generally poor style.

It looks quite obvious that the intent is to increment i by 2; compare with the other clause,

		(progn
		  ;; Compose Cf (format) control characters by
		  ;; replacing with a space.
		  (lglyph-set-char glyph 32)
		  (lglyph-set-width glyph 1)
		  (setq i (1+ i)))

where a character is replaced with a space and we step to the next. In the (non-Cf) clause under scrutiny, we insert a space and, presumably, step past both characters:

	      ;; Compose by prepending a space.
	      (setq gstring (lgstring-insert-glyph gstring i
						   (lglyph-copy glyph))
		    nglyphs (lgstring-glyph-len gstring))
	      (setq glyph (lgstring-glyph gstring i))
	      (lglyph-set-char glyph 32)
	      (lglyph-set-width glyph 1)
	      (setq i (+ 2))

The main question is whether changing the last assignment to (setq i (+ i 2)) would have unintended consequences. As far as I've been able to determine, testing and inspection say no, it should be completely safe.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#63807; Package emacs. (Wed, 31 May 2023 14:30:02 GMT) Full text and rfc822 format available.

Message #14 received at 63807 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Mattias Engdegård <mattias.engdegard <at> gmail.com>
Cc: 63807 <at> debbugs.gnu.org
Subject: Re: bug#63807: bug in compose-gstring-for-terminal?
Date: Wed, 31 May 2023 17:30:25 +0300
> From: Mattias Engdegård <mattias.engdegard <at> gmail.com>
> Date: Wed, 31 May 2023 15:49:23 +0200
> Cc: 63807 <at> debbugs.gnu.org
> 
> 31 maj 2023 kl. 15.02 skrev Eli Zaretskii <eliz <at> gnu.org>:
> 
> > Setting i to 2 is correct there
> 
> Would you explain why to someone who doesn't know how this is supposed to work?

We basically concoct a glyph-string "by hand":

> 	      ;; Compose by prepending a space.
> 	      (setq gstring (lgstring-insert-glyph gstring i
> 						   (lglyph-copy glyph))
> 		    nglyphs (lgstring-glyph-len gstring))
> 	      (setq glyph (lgstring-glyph gstring i))
> 	      (lglyph-set-char glyph 32)
> 	      (lglyph-set-width glyph 1)

> The main question is whether changing the last assignment to (setq i (+ i 2)) would have unintended consequences. As far as I've been able to determine, testing and inspection say no, it should be completely safe.

If we agree that replacing (+ 2) with (+ i 2) is "completely safe",
then we basically agree that this code runs only when i == zero,
right?  Or did I misunderstand what you were saying?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#63807; Package emacs. (Wed, 31 May 2023 15:10:01 GMT) Full text and rfc822 format available.

Message #17 received at 63807 <at> debbugs.gnu.org (full text, mbox):

From: Mattias Engdegård <mattias.engdegard <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 63807 <at> debbugs.gnu.org
Subject: Re: bug#63807: bug in compose-gstring-for-terminal?
Date: Wed, 31 May 2023 17:08:58 +0200
31 maj 2023 kl. 16.30 skrev Eli Zaretskii <eliz <at> gnu.org>:

> If we agree that replacing (+ 2) with (+ i 2) is "completely safe",
> then we basically agree that this code runs only when i == zero,
> right?

Yes -- that is, if we trust external invariants to enforce that it indeed only runs when i is 0. Otherwise, the current code is incorrect and changing it would fix a bug. Either way, changing it should do no harm and has the possibility of improving correctness.

I was unable to provoke that particular code to run for strings longer than 1 chars but that could just be my own ineptitude, and in any case it seems unsafe to rely on it. Maybe you could come up with an example?

(And to answer your question that I edited out in haste: there are no plans to warn about unary applications of `+`. This was just something I stumbled upon while researching something else.)





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#63807; Package emacs. (Wed, 31 May 2023 16:16:01 GMT) Full text and rfc822 format available.

Message #20 received at 63807 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Mattias Engdegård <mattias.engdegard <at> gmail.com>
Cc: 63807 <at> debbugs.gnu.org
Subject: Re: bug#63807: bug in compose-gstring-for-terminal?
Date: Wed, 31 May 2023 19:15:30 +0300
> From: Mattias Engdegård <mattias.engdegard <at> gmail.com>
> Date: Wed, 31 May 2023 17:08:58 +0200
> Cc: 63807 <at> debbugs.gnu.org
> 
> I was unable to provoke that particular code to run for strings longer than 1 chars but that could just be my own ineptitude, and in any case it seems unsafe to rely on it. Maybe you could come up with an example?

I don't think such examples exist, because then we wouldn't need to
prepend a space (the character would compose with the preceding one).

Anyway, if you feel safer to add to i, fine by me (on master, please).




Reply sent to Mattias Engdegård <mattias.engdegard <at> gmail.com>:
You have taken responsibility. (Wed, 31 May 2023 17:25:02 GMT) Full text and rfc822 format available.

Notification sent to Mattias Engdegård <mattias.engdegard <at> gmail.com>:
bug acknowledged by developer. (Wed, 31 May 2023 17:25:02 GMT) Full text and rfc822 format available.

Message #25 received at 63807-done <at> debbugs.gnu.org (full text, mbox):

From: Mattias Engdegård <mattias.engdegard <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 63807-done <at> debbugs.gnu.org
Subject: Re: bug#63807: bug in compose-gstring-for-terminal?
Date: Wed, 31 May 2023 19:23:46 +0200
31 maj 2023 kl. 18.15 skrev Eli Zaretskii <eliz <at> gnu.org>:

> I don't think such examples exist, because then we wouldn't need to
> prepend a space (the character would compose with the preceding one).

Yes, that could very well be the case, but it would take more time and effort to prove it.

> Anyway, if you feel safer to add to i, fine by me (on master, please).

I'll do that, on master naturally. Thank you.






bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Thu, 29 Jun 2023 11:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 301 days ago.

Previous Next


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