Commit 8aa578f3 authored by Ben Boeckel's avatar Ben Boeckel

vtkParsePreprocess: handle realloc errors properly

Change-Id: Ia155fec1bd82642d7e2ce1a1b236f17d32ca4f50
parent d28c44a6
......@@ -276,7 +276,13 @@ static MacroInfo **preproc_macro_location(
if (n > 0 && (n & (n+1)) == 0)
{
hptr = htable[i];
MacroInfo **oldhptr = hptr;
hptr = (MacroInfo **)realloc(hptr, (2*(n+1))*sizeof(MacroInfo *));
if (!hptr)
{
free(oldhptr);
return NULL;
}
htable[i] = hptr;
hptr += n;
}
......@@ -1555,7 +1561,13 @@ const char *preproc_find_include_file(
if (m+1 > outputsize)
{
outputsize += m+1;
char *oldoutput = output;
output = (char *)realloc(output, outputsize);
if (!output)
{
free(oldoutput);
return NULL;
}
}
strncpy(output, filename, m);
output[m] = '\0';
......@@ -1610,7 +1622,13 @@ const char *preproc_find_include_file(
if (m+j+1 > outputsize)
{
outputsize += m+j+1;
char *oldoutput = output;
output = (char *)realloc(output, outputsize);
if (!output)
{
free(oldoutput);
return NULL;
}
}
if (j > 0)
{
......@@ -1624,7 +1642,13 @@ const char *preproc_find_include_file(
if (m+1 > outputsize)
{
outputsize += m+1;
char *oldoutput = output;
output = (char *)realloc(output, outputsize);
if (!output)
{
free(oldoutput);
return NULL;
}
}
strncpy(output, filename, m);
output[m] = '\0';
......@@ -1638,7 +1662,13 @@ const char *preproc_find_include_file(
if (j + m + 2 > outputsize)
{
outputsize += j+m+2;
char *oldoutput = output;
output = (char *)realloc(output, outputsize);
if (!output)
{
free(oldoutput);
return NULL;
}
}
strncpy(output, directory, j);
......@@ -1716,7 +1746,17 @@ void preproc_escape_string(
while (j+4 > linelen)
{
linelen *= 2;
char *oldline = line;
line = (char *)realloc(line, linelen);
if (!line)
{
free(r);
free(oldline);
*linep = NULL;
*linelenp = -1;
*jp = 0; /* XXX: Is this right? */
return;
}
}
if ((r[i] >= ' ' && r[i] <= '~') || (r[i] & 0x80) != 0)
......@@ -1909,7 +1949,13 @@ static int preproc_include_file(
while (j+4 > linelen)
{
linelen *= 2;
char *oldline = line;
line = (char *)realloc(line, linelen);
if (!line)
{
free(oldline);
return VTK_PARSE_OUT_OF_MEMORY;
}
}
/* check for uninteresting characters first */
......
......@@ -112,7 +112,8 @@ enum _preproc_return_t {
VTK_PARSE_FILE_OPEN_ERROR = 8, /* include file not readable */
VTK_PARSE_FILE_READ_ERROR = 9, /* error during read */
VTK_PARSE_MACRO_NUMARGS = 10, /* wrong number of args to func macro */
VTK_PARSE_SYNTAX_ERROR = 11 /* any and all syntax errors */
VTK_PARSE_SYNTAX_ERROR = 11, /* any and all syntax errors */
VTK_PARSE_OUT_OF_MEMORY = 12 /* out-of-memory */
};
/**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment