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

@@ -9,6 +9,7 @@
#include "nvim/ascii_defs.h"
#include "nvim/autocmd.h"
#include "nvim/buffer.h"
#include "nvim/charset.h"
#include "nvim/cursor.h"
#include "nvim/errors.h"
#include "nvim/eval/funcs.h"
@@ -277,8 +278,8 @@ static int get_winnr(tabpage_T *tp, typval_T *argvar)
}
} else {
// Extract the window count (if specified). e.g. winnr('3j')
char *endp;
int count = (int)strtol(arg, &endp, 10);
char *endp = (char *)arg;
int count = getdigits_int(&endp, false, 0);
if (count <= 0) {
// if count is not specified, default to 1
count = 1;