mirror of
https://github.com/reactos/reactos.git
synced 2026-06-01 17:00:51 +08:00
[CMD] Add missing memory allocation NULL checks (#161). CORE-8304
Adapted from a patch by Jacob S. Preciado. Bring also the code suggestions emitted during review.
This commit is contained in:
@@ -188,18 +188,20 @@ BOOL add_entry (LPINT ac, LPTSTR **arg, LPCTSTR entry)
|
||||
LPTSTR *oldarg;
|
||||
|
||||
q = cmd_alloc ((_tcslen(entry) + 1) * sizeof (TCHAR));
|
||||
if (NULL == q)
|
||||
if (!q)
|
||||
{
|
||||
WARN("Cannot allocate memory for q!\n");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
_tcscpy (q, entry);
|
||||
oldarg = *arg;
|
||||
*arg = cmd_realloc (oldarg, (*ac + 2) * sizeof (LPTSTR));
|
||||
if (NULL == *arg)
|
||||
if (!*arg)
|
||||
{
|
||||
cmd_free (q);
|
||||
WARN("Cannot reallocate memory for arg!\n");
|
||||
*arg = oldarg;
|
||||
cmd_free (q);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@@ -222,8 +224,9 @@ static BOOL expand (LPINT ac, LPTSTR **arg, LPCTSTR pattern)
|
||||
if (NULL != pathend)
|
||||
{
|
||||
dirpart = cmd_alloc((pathend - pattern + 2) * sizeof(TCHAR));
|
||||
if (NULL == dirpart)
|
||||
if (!dirpart)
|
||||
{
|
||||
WARN("Cannot allocate memory for dirpart!\n");
|
||||
return FALSE;
|
||||
}
|
||||
memcpy(dirpart, pattern, pathend - pattern + 1);
|
||||
@@ -241,8 +244,9 @@ static BOOL expand (LPINT ac, LPTSTR **arg, LPCTSTR pattern)
|
||||
if (NULL != dirpart)
|
||||
{
|
||||
fullname = cmd_alloc((_tcslen(dirpart) + _tcslen(FindData.cFileName) + 1) * sizeof(TCHAR));
|
||||
if (NULL == fullname)
|
||||
if (!fullname)
|
||||
{
|
||||
WARN("Cannot allocate memory for fullname!\n");
|
||||
ok = FALSE;
|
||||
}
|
||||
else
|
||||
@@ -286,7 +290,10 @@ LPTSTR *split (LPTSTR s, LPINT args, BOOL expand_wildcards, BOOL handle_plus)
|
||||
|
||||
arg = cmd_alloc (sizeof (LPTSTR));
|
||||
if (!arg)
|
||||
{
|
||||
WARN("Cannot allocate memory for arg!\n");
|
||||
return NULL;
|
||||
}
|
||||
*arg = NULL;
|
||||
|
||||
ac = 0;
|
||||
@@ -333,6 +340,7 @@ LPTSTR *split (LPTSTR s, LPINT args, BOOL expand_wildcards, BOOL handle_plus)
|
||||
q = cmd_alloc (((len = s - start) + 1) * sizeof (TCHAR));
|
||||
if (!q)
|
||||
{
|
||||
WARN("Cannot allocate memory for q!\n");
|
||||
return NULL;
|
||||
}
|
||||
memcpy (q, start, len * sizeof (TCHAR));
|
||||
@@ -381,7 +389,10 @@ LPTSTR *splitspace (LPTSTR s, LPINT args)
|
||||
|
||||
arg = cmd_alloc (sizeof (LPTSTR));
|
||||
if (!arg)
|
||||
{
|
||||
WARN("Cannot allocate memory for arg!\n");
|
||||
return NULL;
|
||||
}
|
||||
*arg = NULL;
|
||||
|
||||
ac = 0;
|
||||
@@ -409,6 +420,7 @@ LPTSTR *splitspace (LPTSTR s, LPINT args)
|
||||
q = cmd_alloc (((len = s - start) + 1) * sizeof (TCHAR));
|
||||
if (!q)
|
||||
{
|
||||
WARN("Cannot allocate memory for q!\n");
|
||||
return NULL;
|
||||
}
|
||||
memcpy (q, start, len * sizeof (TCHAR));
|
||||
|
||||
Reference in New Issue
Block a user