[vim/vim] Reject non-string-literal arguments to STRLEN_LITERAL (PR #21122)
Shane Harper (Vim Github Repository) <[email protected]>
| Newsgroups | gmane.editors.vim.devel |
|---|---|
| Message-ID | <vim/vim/pull/[email protected]> |
**Problem:** STRLEN_LITERAL silently expands to an expression that doesn't
determine a string's length if it's given a non-string-literal
token.
**Solution:** Modify STRLEN_LITERAL so that a non-string-literal argument
produces a compile error.
_Regarding character arrays:_
A compilation error will now be generated for the following:
`char s[64] = "12345";`
`int l = STRLEN_LITERAL(s); // previously l was assigned 63 (not 5).`
Had `s` been defined as:
`char s[] = "12345";`
the original definition of STRLEN_LITERAL would have correctly
determined the string length to be 5; however, the macro cannot
distinguish a padded array like the first from an exactly-sized one like
the second, so both are rejected.
_Regarding PATHSEPSTR:_
On MS-Windows, PATHSEPSTR does not expand to a string-literal token, so
STRLEN_LITERAL(PATHSEPSTR) fails to compile. Each
STRLEN_LITERAL(PATHSEPSTR) is replaced with sizeof(PATHSEP).
sizeof(PATHSEP) is now always 1; previously it was 1 (sizeof(char_u)) on
MS-Windows but sizeof(int) elsewhere. (PATHSEP is a single character;
PATHSEPSTR is a null-terminated string with a single content byte
followed by NUL.)
Supported by AI (Claude Sonnet 5).
You can view, comment on, or merge this pull request online at:
https://github.com/vim/vim/pull/21122
-- Commit Summary --
* Reject non-string-literal arguments to STRLEN_LITERAL
* Fix MS-Windows build
-- File Changes --
M src/ascii.h (2)
M src/cmdexpand.c (2)
M src/fileio.c (4)
M src/filepath.c (4)
M src/findfile.c (2)
M src/help.c (2)
M src/os_unix.c (2)
M src/scriptfile.c (2)
M src/structs.h (8)
-- Patch Links --
https://github.com/vim/vim/pull/21122.patch
https://github.com/vim/vim/pull/21122.diff
--
Reply to this email directly or view it on GitHub:
https://github.com/vim/vim/pull/21122
You are receiving this because you are subscribed to this thread.
Message ID: <vim/vim/pull/[email protected]>
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups "vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion visit https://groups.google.com/d/msgid/vim_dev/vim/vim/pull/21122%40github.com.