From f2b85d2a79d8398bd4b9ff39eca9670c00cb8400 Mon Sep 17 00:00:00 2001 From: Timo Kreuzer Date: Mon, 19 Jan 2026 17:57:56 +0200 Subject: [PATCH] [CMD] Fix GCC 13 use-after-free warning Make the code simpler, so GCC doesn't get confused. C:/ReactOS/reactos/base/shell/cmd/misc.c: In function 'add_entry': C:/ReactOS/reactos/base/shell/cmd/misc.c:216:14: error: pointer 'oldarg' may be used after 'realloc' [-Werror=use-after-free] 216 | *arg = oldarg; | ~~~~~^~~~~~~~ In file included from C:/ReactOS/reactos/base/shell/cmd/cmd.h:29, from C:/ReactOS/reactos/base/shell/cmd/precomp.h:34, from C:/ReactOS/reactos/base/shell/cmd/misc.c:35: C:/ReactOS/reactos/base/shell/cmd/cmddbg.h:30:31: note: call to 'realloc' here 30 | #define cmd_realloc(ptr,size) realloc(ptr, size) | ^~~~~~~~~~~~~~~~~~ C:/ReactOS/reactos/base/shell/cmd/misc.c:212:12: note: in expansion of macro 'cmd_realloc' 212 | *arg = cmd_realloc (oldarg, (*ac + 2) * sizeof (LPTSTR)); | ^~~~~~~~~~~ --- base/shell/cmd/misc.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/base/shell/cmd/misc.c b/base/shell/cmd/misc.c index 1386cf57e93..8b5753f7b14 100644 --- a/base/shell/cmd/misc.c +++ b/base/shell/cmd/misc.c @@ -198,7 +198,7 @@ BOOL CheckCtrlBreak(INT mode) BOOL add_entry (LPINT ac, LPTSTR **arg, LPCTSTR entry) { LPTSTR q; - LPTSTR *oldarg; + LPTSTR *newarg; q = cmd_alloc ((_tcslen(entry) + 1) * sizeof (TCHAR)); if (!q) @@ -208,16 +208,16 @@ BOOL add_entry (LPINT ac, LPTSTR **arg, LPCTSTR entry) } _tcscpy (q, entry); - oldarg = *arg; - *arg = cmd_realloc (oldarg, (*ac + 2) * sizeof (LPTSTR)); - if (!*arg) + newarg = cmd_realloc (*arg, (*ac + 2) * sizeof (LPTSTR)); + if (!newarg) { WARN("Cannot reallocate memory for arg!\n"); - *arg = oldarg; cmd_free (q); return FALSE; } + *arg = newarg; + /* save new entry */ (*arg)[*ac] = q; (*arg)[++(*ac)] = NULL;