Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Extend usage of const char*



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(-)






Messages sorted by: Reverse Date, Date, Thread, Author