mirror of
https://github.com/reactos/reactos.git
synced 2026-06-06 05:09:11 +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:
@@ -96,9 +96,13 @@ static LPTSTR ReadFileContents(FILE *InputFile, TCHAR *Buffer)
|
||||
{
|
||||
SIZE_T Len = 0;
|
||||
SIZE_T AllocLen = 1000;
|
||||
|
||||
LPTSTR Contents = cmd_alloc(AllocLen * sizeof(TCHAR));
|
||||
if (!Contents)
|
||||
{
|
||||
WARN("Cannot allocate memory for Contents!\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
while (_fgetts(Buffer, CMDLINE_LENGTH, InputFile))
|
||||
{
|
||||
@@ -109,6 +113,7 @@ static LPTSTR ReadFileContents(FILE *InputFile, TCHAR *Buffer)
|
||||
Contents = cmd_realloc(Contents, (AllocLen *= 2) * sizeof(TCHAR));
|
||||
if (!Contents)
|
||||
{
|
||||
WARN("Cannot reallocate memory for Contents!\n");
|
||||
cmd_free(OldContents);
|
||||
return NULL;
|
||||
}
|
||||
@@ -454,7 +459,7 @@ static INT ForRecursive(PARSED_COMMAND *Cmd, LPTSTR List, TCHAR *Buffer, TCHAR *
|
||||
return Ret;
|
||||
}
|
||||
|
||||
BOOL
|
||||
INT
|
||||
ExecuteFor(PARSED_COMMAND *Cmd)
|
||||
{
|
||||
TCHAR Buffer[CMDLINE_LENGTH]; /* Buffer to hold the variable value */
|
||||
@@ -470,6 +475,7 @@ ExecuteFor(PARSED_COMMAND *Cmd)
|
||||
lpNew = cmd_alloc(sizeof(FOR_CONTEXT));
|
||||
if (!lpNew)
|
||||
{
|
||||
WARN("Cannot allocate memory for lpNew!\n");
|
||||
cmd_free(List);
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user