Skip to content

Commit 0aa05b1

Browse files
committed
Remove VLA in cmd_emacs_just_one_space
The count is clamped to a constant bound, so a fixed-size buffer suffices. The bound is now a named constant. Part of #239.
1 parent cf3a3a1 commit 0aa05b1

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

lineedit/editing.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* Yash: yet another shell */
22
/* editing.c: main editing module */
3-
/* (C) 2007-2025 magicant */
3+
/* (C) 2007-2026 magicant */
44

55
/* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -3247,13 +3247,14 @@ void cmd_emacs_delete_horizontal_space(wchar_t c __attribute__((unused)))
32473247
* If the count is specified, blanks are replaced with `count' spaces. */
32483248
void cmd_emacs_just_one_space(wchar_t c __attribute__((unused)))
32493249
{
3250+
#define MAX_SPACE_COUNT 1000 /* The count is limited to avoid overflow. */
32503251
int count = get_count(1);
32513252
if (count < 0)
32523253
count = 0;
3253-
else if (count > 1000)
3254-
count = 1000;
3254+
else if (count > MAX_SPACE_COUNT)
3255+
count = MAX_SPACE_COUNT;
32553256

3256-
wchar_t s[count + 1];
3257+
wchar_t s[MAX_SPACE_COUNT + 1];
32573258
wmemset(s, L' ', count);
32583259
s[count] = L'\0';
32593260

0 commit comments

Comments
 (0)