From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 28055 invoked from network); 16 Feb 2023 23:36:38 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 16 Feb 2023 23:36:38 -0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Message-ID:Date: Content-Transfer-Encoding:Content-ID:Content-Type:MIME-Version:Subject:To: References:From:In-reply-to:cc:Reply-To:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=wDpnIm5LGFJlEzqAs41hMSjLpkz0lYC8P2Ls50wfObk=; b=PEeFJCYikcB4OFsNSyWsgSpylJ SuTd1r84nQZfIY0BrknHJAdpyGZ5rtj8aoGTFNRCzE6GWbQa0eXPUZMd8ZLbbhLTsT+4I6pyIH4ML PD5XJEMWwaF0cfTajREQIst8Uu8bjQ1LN+FonlWvO1XENPeYQFWhtkA4ywFd7PMBMhQA4QYsoYCux L7bw8w/8IPcOCnRqqiD98R/np3cjvfUDDqBarI85PY7PDJF2uheSEcj+SBOocEG8pY3fN9q0kRl2R U0fMhi77X/ftbTmzT4WRqM6MBBjUqroHil/Gy9PKjRpIno2RdKK9M8E6Yb0YsCS+qFctE07YvXLti 0riQt9SA==; Received: by zero.zsh.org with local id 1pSnnq-000Nvn-MH; Thu, 16 Feb 2023 23:36:38 +0000 Received: by zero.zsh.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1pSnnf-000Nd8-GN; Thu, 16 Feb 2023 23:36:27 +0000 Received: from [192.168.178.21] (helo=hydra) by mail.kiddle.eu with esmtp(Exim 4.95) (envelope-from ) id 1pSnne-0008Bp-UA; Fri, 17 Feb 2023 00:36:27 +0100 cc: Zsh hackers list In-reply-to: From: Oliver Kiddle References: To: Bart Schaefer Subject: Re: Build warning in zle_keymap.c MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <31483.1676590586.1@hydra> Content-Transfer-Encoding: 8bit Date: Fri, 17 Feb 2023 00:36:26 +0100 Message-ID: <31484-1676590586.931773@e-C5.Q4TC.wUAo> X-Seq: 51447 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: 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; } }