]> git.ipfire.org Git - thirdparty/vim.git/commit
patch 9.2.0370: duplicate code with literal string_T assignment v9.2.0370
authorHirohito Higashi <h.east.727@gmail.com>
Mon, 20 Apr 2026 14:43:52 +0000 (14:43 +0000)
committerChristian Brabandt <cb@256bit.org>
Mon, 20 Apr 2026 14:43:52 +0000 (14:43 +0000)
commit2c436be6f7b4436dc2de4b4dd2a8d1ce0f948748
tree5d8325d081c3c4403666905fd2555639b661f395
parent6ecff78129307676f74c68bd08648465f980c6fd
patch 9.2.0370: duplicate code with literal string_T assignment

Problem:  Duplicate code with literal string_T assignment
Solution: Add STR_LITERAL_SET() macro for string_T literal assignment
          (Hirohito Higashi).

Previously, assigning a string literal to a string_T variable required
two lines that repeated the literal:

    s.string = (char_u *)"open";
    s.length = STRLEN_LITERAL("open");

Writing the literal twice is error-prone -- a typo in one of them
leaves the pointer and the cached length out of sync.

Add a STR_LITERAL_SET() macro in macros.h so that the assignment can
be written in one statement with the literal appearing only once:

    STR_LITERAL_SET(s, "open");

Replace all occurrences of the two-line pattern across the codebase
with the new macro.

No functional change.

related: #19999
related: #20023
closes:  #20025

Signed-off-by: Hirohito Higashi <h.east.727@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/autocmd.c
src/channel.c
src/eval.c
src/fileio.c
src/macros.h
src/os_win32.c
src/scriptfile.c
src/strings.c
src/textprop.c
src/version.c
src/vim9type.c