cpplib.c (glue_header_name): Use local buffer to build up header name.
* cpplib.c (glue_header_name): Use local buffer to build up header name. From-SVN: r49998
This commit is contained in:
parent
70b6aaed80
commit
2450e0b8ea
@ -1,3 +1,8 @@
|
|||||||
|
2002-02-23 Neil Booth <neil@daikokuya.demon.co.uk>
|
||||||
|
|
||||||
|
* cpplib.c (glue_header_name): Use local buffer to build up
|
||||||
|
header name.
|
||||||
|
|
||||||
2002-02-23 Neil Booth <neil@daikokuya.demon.co.uk>
|
2002-02-23 Neil Booth <neil@daikokuya.demon.co.uk>
|
||||||
|
|
||||||
* doc/cpp.texi, doc/invoke.texi: Update documentation for -MM.
|
* doc/cpp.texi, doc/invoke.texi: Update documentation for -MM.
|
||||||
|
32
gcc/cpplib.c
32
gcc/cpplib.c
@ -507,13 +507,12 @@ glue_header_name (pfile)
|
|||||||
{
|
{
|
||||||
cpp_token *header = NULL;
|
cpp_token *header = NULL;
|
||||||
const cpp_token *token;
|
const cpp_token *token;
|
||||||
unsigned char *dest;
|
unsigned char *buffer;
|
||||||
size_t len;
|
size_t len, total_len = 0, capacity = 1024;
|
||||||
|
|
||||||
/* To avoid lexed tokens overwriting our glued name, we can only
|
/* To avoid lexed tokens overwriting our glued name, we can only
|
||||||
allocate from the string pool once we've lexed everything. */
|
allocate from the string pool once we've lexed everything. */
|
||||||
|
buffer = (unsigned char *) xmalloc (capacity);
|
||||||
dest = BUFF_FRONT (pfile->u_buff);
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
token = cpp_get_token (pfile);
|
token = cpp_get_token (pfile);
|
||||||
@ -521,34 +520,35 @@ glue_header_name (pfile)
|
|||||||
if (token->type == CPP_GREATER || token->type == CPP_EOF)
|
if (token->type == CPP_GREATER || token->type == CPP_EOF)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* + 1 for terminating NUL. */
|
len = cpp_token_len (token);
|
||||||
len = cpp_token_len (token) + 1;
|
if (total_len + len > capacity)
|
||||||
if ((size_t) (BUFF_LIMIT (pfile->u_buff) - dest) < len)
|
|
||||||
{
|
{
|
||||||
size_t len_so_far = dest - BUFF_FRONT (pfile->u_buff);
|
capacity = (capacity + len) * 2;
|
||||||
_cpp_extend_buff (pfile, &pfile->u_buff, len);
|
buffer = (unsigned char *) xrealloc (buffer, capacity);
|
||||||
dest = BUFF_FRONT (pfile->u_buff) + len_so_far;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (token->flags & PREV_WHITE)
|
if (token->flags & PREV_WHITE)
|
||||||
*dest++ = ' ';
|
buffer[total_len++] = ' ';
|
||||||
|
|
||||||
dest = cpp_spell_token (pfile, token, dest);
|
total_len = cpp_spell_token (pfile, token, &buffer[total_len]) - buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (token->type == CPP_EOF)
|
if (token->type == CPP_EOF)
|
||||||
cpp_error (pfile, "missing terminating > character");
|
cpp_error (pfile, "missing terminating > character");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
unsigned char *token_mem = _cpp_unaligned_alloc (pfile, total_len + 1);
|
||||||
|
memcpy (token_mem, buffer, total_len);
|
||||||
|
token_mem[total_len] = '\0';
|
||||||
|
|
||||||
header = _cpp_temp_token (pfile);
|
header = _cpp_temp_token (pfile);
|
||||||
header->type = CPP_HEADER_NAME;
|
header->type = CPP_HEADER_NAME;
|
||||||
header->flags = 0;
|
header->flags = 0;
|
||||||
header->val.str.len = dest - BUFF_FRONT (pfile->u_buff);
|
header->val.str.len = total_len;
|
||||||
header->val.str.text = BUFF_FRONT (pfile->u_buff);
|
header->val.str.text = token_mem;
|
||||||
*dest++ = '\0';
|
|
||||||
BUFF_FRONT (pfile->u_buff) = dest;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free ((PTR) buffer);
|
||||||
return header;
|
return header;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user