zsh-workers
 help / color / mirror / code / Atom feed
* Build warning in zle_keymap.c
@ 2023-02-15  2:35 Bart Schaefer
  2023-02-16 23:36 ` Oliver Kiddle
  0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2023-02-15  2:35 UTC (permalink / raw)
  To: Zsh hackers list

I just recompiled from a complete "make clean; rm config.modules;
./configure" for the first time in several months and:

zle_keymap.c: In function ‘getkeymapcmd’:
zle_keymap.c:1656:27: warning: ‘startcsi’ may be used uninitialized in
this function [-Wmaybe-uninitialized]
 1656 |       lastlen <= startcsi + 2) {
      |                  ~~~~~~~~~^~~


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Build warning in zle_keymap.c
  2023-02-15  2:35 Build warning in zle_keymap.c Bart Schaefer
@ 2023-02-16 23:36 ` Oliver Kiddle
  2023-02-17  0:36   ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: Oliver Kiddle @ 2023-02-16 23:36 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh hackers list

Bart Schaefer wrote:
> I just recompiled from a complete "make clean; rm config.modules;
> ./configure" for the first time in several months and:
>
> zle_keymap.c: In function ‘getkeymapcmd’:
> zle_keymap.c:1656:27: warning: ‘startcsi’ may be used uninitialized in
> this function [-Wmaybe-uninitialized]
>  1656 |       lastlen <= startcsi + 2) {
>       |                  ~~~~~~~~~^~~

If you follow the logic, it isn't actually possible so the warning is
wrong.

Where csi is false, the value of startcsi is irrelevant so we can
replace both with just one variable, either by using -1 as the false
value or changing the startcsi offset (it can be zero). The patch below
takes the latter approach. csi is now either 0 (meaning false/not
in a CSI sequence) or points to the offset in keybuf to the first
character after \e[ (which can't be zero). That isn't the start of the
CSI sequence so I kept csi and dropped startcsi.
Does this silence the compiler?

Oliver

diff --git a/Src/Zle/zle_keymap.c b/Src/Zle/zle_keymap.c
index ec8dd031e..a31ab22d7 100644
--- a/Src/Zle/zle_keymap.c
+++ b/Src/Zle/zle_keymap.c
@@ -1586,7 +1586,7 @@ getkeymapcmd(Keymap km, Thingy *funcp, char **strp)
     Thingy func = t_undefinedkey;
     char *str = NULL;
     int lastlen = 0, lastc = lastchar;
-    int timeout = 0, csi = 0, startcsi;
+    int timeout = 0, csi = 0;
 
     keybuflen = 0;
     keybuf[0] = 0;
@@ -1640,22 +1640,23 @@ getkeymapcmd(Keymap km, Thingy *funcp, char **strp)
 	/* CSI key sequences have a well defined structure so if we currently
 	 * have an incomplete one, loop so the rest of it will be included in
 	 * the key sequence if that arrives within the timeout. */
-	if (keybuflen >= 3 && !csi) {
-	    startcsi = keybuflen - 3;
-	    csi = keybuf[startcsi] == '\033' && keybuf[keybuflen - 2] == '[';
-	}
+	if (!csi && keybuflen >= 3 && keybuf[keybuflen - 3] == '\033' &&
+		keybuf[keybuflen - 2] == '[')
+	    csi = keybuflen - 1;
 	if (csi) {
-	    csi = keybuf[keybuflen - 2] != Meta && keybuf[keybuflen - 1] >= 0x20
-		&& keybuf[keybuflen - 1] <= 0x3f;
+	    if (keybuf[keybuflen - 2] == Meta || keybuf[keybuflen - 1] < 0x20
+		   || keybuf[keybuflen - 1] > 0x3f) {
 	    /* If we reach the end of a valid CSI sequence and the matched key
 	     * binding is for part of the CSI introduction, select instead the
 	     * undefined-key widget and consume the full sequence from the
 	     * input buffer. */
-	    if (!csi && keybuf[keybuflen - 1] >= 0x40 &&
-		    keybuf[keybuflen - 1] <= 0x7e && lastlen > startcsi &&
-		    lastlen <= startcsi + 2) {
-		func = t_undefinedkey;
-		lastlen = keybuflen;
+		if (keybuf[keybuflen - 1] >= 0x40 &&
+			keybuf[keybuflen - 1] <= 0x7e && lastlen > csi - 2 &&
+			lastlen <= csi) {
+		    func = t_undefinedkey;
+		    lastlen = keybuflen;
+		}
+		csi = 0;
 	    }
 	}
 


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Build warning in zle_keymap.c
  2023-02-16 23:36 ` Oliver Kiddle
@ 2023-02-17  0:36   ` Bart Schaefer
  0 siblings, 0 replies; 3+ messages in thread
From: Bart Schaefer @ 2023-02-17  0:36 UTC (permalink / raw)
  To: Oliver Kiddle; +Cc: Zsh hackers list

On Thu, Feb 16, 2023 at 3:36 PM Oliver Kiddle <opk@zsh.org> wrote:
>
> Does this silence the compiler?

It does.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-02-17  0:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-15  2:35 Build warning in zle_keymap.c Bart Schaefer
2023-02-16 23:36 ` Oliver Kiddle
2023-02-17  0:36   ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).