* bug#63807: bug in compose-gstring-for-terminal?
@ 2023-05-30 20:36 Mattias Engdegård
2023-05-31 13:02 ` Eli Zaretskii
0 siblings, 1 reply; 7+ messages in thread
From: Mattias Engdegård @ 2023-05-30 20:36 UTC (permalink / raw)
To: 63807
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.
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#63807: bug in compose-gstring-for-terminal?
2023-05-30 20:36 bug#63807: bug in compose-gstring-for-terminal? Mattias Engdegård
@ 2023-05-31 13:02 ` Eli Zaretskii
2023-05-31 13:49 ` Mattias Engdegård
0 siblings, 1 reply; 7+ messages in thread
From: Eli Zaretskii @ 2023-05-31 13:02 UTC (permalink / raw)
To: Mattias Engdegård; +Cc: 63807
> From: Mattias Engdegård <mattias.engdegard@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.
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#63807: bug in compose-gstring-for-terminal?
2023-05-31 13:02 ` Eli Zaretskii
@ 2023-05-31 13:49 ` Mattias Engdegård
2023-05-31 14:30 ` Eli Zaretskii
0 siblings, 1 reply; 7+ messages in thread
From: Mattias Engdegård @ 2023-05-31 13:49 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 63807
31 maj 2023 kl. 15.02 skrev Eli Zaretskii <eliz@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.
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#63807: bug in compose-gstring-for-terminal?
2023-05-31 13:49 ` Mattias Engdegård
@ 2023-05-31 14:30 ` Eli Zaretskii
2023-05-31 15:08 ` Mattias Engdegård
0 siblings, 1 reply; 7+ messages in thread
From: Eli Zaretskii @ 2023-05-31 14:30 UTC (permalink / raw)
To: Mattias Engdegård; +Cc: 63807
> From: Mattias Engdegård <mattias.engdegard@gmail.com>
> Date: Wed, 31 May 2023 15:49:23 +0200
> Cc: 63807@debbugs.gnu.org
>
> 31 maj 2023 kl. 15.02 skrev Eli Zaretskii <eliz@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?
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#63807: bug in compose-gstring-for-terminal?
2023-05-31 14:30 ` Eli Zaretskii
@ 2023-05-31 15:08 ` Mattias Engdegård
2023-05-31 16:15 ` Eli Zaretskii
0 siblings, 1 reply; 7+ messages in thread
From: Mattias Engdegård @ 2023-05-31 15:08 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 63807
31 maj 2023 kl. 16.30 skrev Eli Zaretskii <eliz@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.)
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#63807: bug in compose-gstring-for-terminal?
2023-05-31 15:08 ` Mattias Engdegård
@ 2023-05-31 16:15 ` Eli Zaretskii
2023-05-31 17:23 ` Mattias Engdegård
0 siblings, 1 reply; 7+ messages in thread
From: Eli Zaretskii @ 2023-05-31 16:15 UTC (permalink / raw)
To: Mattias Engdegård; +Cc: 63807
> From: Mattias Engdegård <mattias.engdegard@gmail.com>
> Date: Wed, 31 May 2023 17:08:58 +0200
> Cc: 63807@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).
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#63807: bug in compose-gstring-for-terminal?
2023-05-31 16:15 ` Eli Zaretskii
@ 2023-05-31 17:23 ` Mattias Engdegård
0 siblings, 0 replies; 7+ messages in thread
From: Mattias Engdegård @ 2023-05-31 17:23 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 63807-done
31 maj 2023 kl. 18.15 skrev Eli Zaretskii <eliz@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.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2023-05-31 17:23 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-30 20:36 bug#63807: bug in compose-gstring-for-terminal? Mattias Engdegård
2023-05-31 13:02 ` Eli Zaretskii
2023-05-31 13:49 ` Mattias Engdegård
2023-05-31 14:30 ` Eli Zaretskii
2023-05-31 15:08 ` Mattias Engdegård
2023-05-31 16:15 ` Eli Zaretskii
2023-05-31 17:23 ` Mattias Engdegård
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.