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.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 23110 invoked from network); 1 Jan 2024 18:27:12 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 1 Jan 2024 18:27:12 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1704133632; b=Nksy05cvFCyA/vKK4p1ic7PxzqgdFeq0W5sKo7Sw7QTo1wsjiMXGr7AN054S+Lcdq0URpw5wwp 9t8Qrkac4r6LvUw0LYkW2fmR++13+mUzTRD3QF47OiD96LEEdHUeuNt+n0JBnad9PS/hzf7Ene Vw4ps29TPRMJvYHom7oPsffs3hpnKsKrsZ/WUDmclSKQcB4eVuNIKoFN5tLMvOjjmLjW6hpTJ1 Gge+vc8sM49iuvrXwTIaAvIkOwoW7YxRJf0KHH+3bqjXarGJOLX0Vl0xqVUVSqZ4by8H7rXDOe znPR3AwqA0iyLjS1MyQQ6eDdGhv+fUZQ5VygN+coPYTMpQ==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (s1.jo-so.de) smtp.remote-ip=37.221.195.157; dmarc=none header.from=jo-so.de; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1704133632; bh=mjs4G8ZoyoNa6+eoA9O6oM5ohv0oRox57sN0dGQvsro=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:Content-Type:MIME-Version: Message-ID:Date:Subject:To:From:DKIM-Signature; b=hLq0XfjoYO2kUaZw65Av0O4IeYLlQKdK54HRsRP628+NSr+IKjIRlI026pbjtF6uKBwkPvCJqC AgWs8ZZxVPnHj7BrDP0t3rwdGYgI1BChFI9qSIwm9aoOB10Zc5F/oFcQlo6gQVx9FplTw6aiwF WccACxMJIEYTgOeCtS7cZU++REL3Rm2n+7ZXs3kavjvxsEShPF++oqRu0d9O6W57w89WhjG/lS +DsEJs7sM7gS5/ArT4vW6e6XRBly4hsINoHCl6LClDo87xlO57SOr9nKhRKKEmomMmoGh3hJ8I ANJ5PYLTorlo3T2J5kTmg5MmYP85tkdOsi0r1BqmfpkFEA==; 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:Content-Transfer-Encoding: Content-Type:MIME-Version:Message-ID:Date:Subject:To:From:Reply-To:Cc: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References; bh=MumpW50XpPQOiNTDX2LNxv89abIUALAtRWXnKtq/Ygk=; b=YVQV8h6RW/n2x54pbTIWSUoVKr QICVjdi2LsYSbDN1Uxi5F2SogNVYl78oHHQKtHFNNCZ9nNnwvYSw8L1YDG814tEvj8Utqg7IuXGQF wnpAvr5BlOEgbVeezelxndvXuaFWAnVQ/DQxfK/wZ6jqd9v5VRiBiQDuX14HLWfKvCC+DOWqRglZq pWRKyyBFtbmf1qm7P4EJoIib/eEknHpqS4iZ914gQWX0Hda/OxwV6aIp4maGO5ue7JkZJ0vKRSOpS q+KIAbtxVFx15TlQIeO/DgE4i/DrObi5jy84qB8sJo6VjTkD7S7Yfx3hcYNWKqpd9z7fJHhcjPgV8 lsmQ7K+g==; Received: by zero.zsh.org with local id 1rKN0H-000M68-Tj; Mon, 01 Jan 2024 18:27:10 +0000 Authentication-Results: zsh.org; iprev=pass (s1.jo-so.de) smtp.remote-ip=37.221.195.157; dmarc=none header.from=jo-so.de; arc=none Received: from s1.jo-so.de ([37.221.195.157]:45731) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1rKN00-000LmT-71; Mon, 01 Jan 2024 18:26:53 +0000 Received: from mail-relay (helo=jo-so.de) by s1.jo-so.de with local-bsmtp (Exim 4.96) (envelope-from ) id 1rKMzy-0040Eh-2i for zsh-workers@zsh.org; Mon, 01 Jan 2024 19:26:50 +0100 Received: from joerg by zenbook.jo-so.de with local (Exim 4.97) (envelope-from ) id 1rKMzl-00000001ohX-0m2B for zsh-workers@zsh.org; Mon, 01 Jan 2024 19:26:37 +0100 From: =?UTF-8?q?J=C3=B6rg=20Sommer?= To: zsh-workers@zsh.org Subject: Extend usage of const char* Date: Mon, 1 Jan 2024 19:10:15 +0100 Message-ID: <20240101182608.432886-1-joerg@jo-so.de> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Seq: 52438 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: The compiler option `-Wwrite-strings` brings up many places where a string literal (`const char*`) gets assigned to a variable whose type (`char*`) allows modifications of the string content. If the DATA segment of the ELF binary is mapped as read-only, this leads to a segmentation violation and crashes the process. But even without a crash, the compiler could do better checks and optimizations, if the variables have the appropriate type. These patches are the beginning of a series of many commits—if you like. So, please tell, if I should merge commits, reorder or rewrite them. Many of them are trivial changes of adding `const` to the variable declaration. But some of them require code rearrangements or rewrites. Hence, I plan to commit one file at a time, if possible. [PATCH 1/6] zle.textobjects: Mark variables as const [PATCH 2/6] lex: Mark variables with const init as const [PATCH 3/6] zle_vi: Mark variables with const init as const [PATCH 4/6] zle_main: mark statusline as const [PATCH 5/6] module: Mark name argument of some functions const [PATCH 6/6] zsh: mark hookdef.name as const Src/Zle/textobjects.c | 6 +++--- Src/Zle/zle_main.c | 2 +- Src/Zle/zle_vi.c | 2 +- Src/lex.c | 6 +++--- Src/module.c | 15 ++++++++------- Src/zsh.h | 2 +- 6 files changed, 17 insertions(+), 16 deletions(-)