build: lint "strtol" #40442

Problem:
No lint for strtol().

Solution:
Add lint, and update existing usages.

Callers that previously got a (garbage) large positive value:
- `indent.c`: use getdigits() (intmax, no int truncation) with def=1 so
  overflow/too-large values stay positive and fall through to the
  existing "too big" check (E475).
- `file_search.c`: use getdigits() with def=255 so overflow/too-large
  values keep the "max expand" (else) branch.

The other conversions (api/command.c, eval/window.c, highlight_group.c,
tui/tui.c) only diverge on pathological overflow inputs where strtol's
result was already garbage and the observable outcome is unchanged.
This commit is contained in:
Justin M. Keyes
2026-06-28 19:01:24 -04:00
committed by GitHub
parent bb6576c92a
commit 87b42e1209
9 changed files with 37 additions and 12 deletions

View File

@@ -1088,6 +1088,20 @@ local function check_language(filename, clean_lines, linenum, error)
)
end
-- Check for strtol: it silently overflows/truncates and needs error-prone boilerplate.
-- TODO: also flag atoi, atol, atoll, strtoul, strtoll, strtoull.
local strtol_regex = vim.regex([[\<strtol\>]])
if strtol_regex:match_str(line) then
error(
filename,
linenum,
'runtime/deprecated',
4,
'Use getdigits()/getdigits_int() (or vim_str2nr() for non-decimal bases) instead of strtol, '
.. 'which overflows silently. See src/nvim/charset.c.'
)
end
-- Check for memset with wrong argument order: memset(buf, sizeof(buf), 0)
-- Pattern: memset(arg1, arg2, 0) where arg2 is NOT a valid fill value
local memset_start = line:find('memset%s*%([^)]*,%s*[^,]*,%s*0%s*%)')