diff options
author | zack <zack@138bc75d-0d04-0410-961f-82ee72b054a4> | 2000-04-16 02:18:52 +0000 |
---|---|---|
committer | zack <zack@138bc75d-0d04-0410-961f-82ee72b054a4> | 2000-04-16 02:18:52 +0000 |
commit | 57f9dbdc27af07d621d5ee24333e72afa86ebb70 (patch) | |
tree | d124b776a65bba44c571b2da18a91a1cd3fb95aa /gcc/cpplex.c | |
parent | a4b4a9403a471519ae3602b866b0be0006a74a7c (diff) | |
download | gcc-57f9dbdc27af07d621d5ee24333e72afa86ebb70.tar.gz |
* cpplex.c (output_line_command): Remove debugging prints.
(cpp_output_tokens): Don't write out a zero-length buffer or
try to see if it has a newline in it.
(_cpp_expand_to_buffer): Copy the source buffer before pushing.
(_cpp_read_and_prescan): Move shift-down of pushback bytes to
the end of the loop. Use memmove. Don't read past the end of
the buffer. Remove trailing newlines from error messages.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@33180 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cpplex.c')
-rw-r--r-- | gcc/cpplex.c | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/gcc/cpplex.c b/gcc/cpplex.c index 08133595a71..f4f7c8def67 100644 --- a/gcc/cpplex.c +++ b/gcc/cpplex.c @@ -165,8 +165,6 @@ output_line_command (pfile, print) return; line = CPP_BUF_LINE (ip); - // fprintf (print->outf, "[%u %u", print->lineno, line); - /* Determine whether the current filename has changed, and if so, how. 'nominal_fname' values are unique, so they can be compared by comparing pointers. */ @@ -199,7 +197,6 @@ output_line_command (pfile, print) putc ('\n', print->outf); print->lineno++; } - // putc(']', print->outf); return; } @@ -226,10 +223,13 @@ cpp_output_tokens (pfile, print) cpp_reader *pfile; cpp_printer *print; { - if (CPP_PWRITTEN (pfile)[-1] == '\n' && print->lineno) - print->lineno++; - safe_fwrite (pfile, pfile->token_buffer, - CPP_WRITTEN (pfile) - print->written, print->outf); + if (CPP_WRITTEN (pfile) - print->written) + { + if (CPP_PWRITTEN (pfile)[-1] == '\n' && print->lineno) + print->lineno++; + safe_fwrite (pfile, pfile->token_buffer, + CPP_WRITTEN (pfile) - print->written, print->outf); + } output_line_command (pfile, print); CPP_SET_WRITTEN (pfile, print->written); } @@ -245,6 +245,7 @@ _cpp_expand_to_buffer (pfile, buf, length) { cpp_buffer *ip; enum cpp_ttype token; + U_CHAR *buf1; if (length < 0) { @@ -252,8 +253,14 @@ _cpp_expand_to_buffer (pfile, buf, length) return; } + /* Copy the buffer, because it might be in an unsafe place - for + example, a sequence on the token_buffer, where the pointers will + be invalidated if we enlarge the token_buffer. */ + buf1 = alloca (length); + memcpy (buf1, buf, length); + /* Set up the input on the input stack. */ - ip = cpp_push_buffer (pfile, buf, length); + ip = cpp_push_buffer (pfile, buf1, length); if (ip == NULL) return; ip->has_escapes = 1; @@ -1631,12 +1638,6 @@ _cpp_read_and_prescan (pfile, fp, desc, len) { U_CHAR *near_buff_end; - /* Copy previous char plus unprocessed (at most 2) chars - to beginning of buffer, refill it with another - read(), and continue processing */ - memcpy(ip - count - 1, ip - 1, 3); - ip -= count; - count = read (desc, ibase, pfile->input_buffer_len); if (count < 0) goto error; @@ -1785,6 +1786,11 @@ _cpp_read_and_prescan (pfile, fp, desc, len) break; } } + /* Copy previous char plus unprocessed (at most 2) chars + to beginning of buffer, refill it with another + read(), and continue processing */ + memmove (ip - count - 1, ip - 1, 4 - (ip - near_buff_end)); + ip -= count; } if (offset == 0) @@ -1795,7 +1801,7 @@ _cpp_read_and_prescan (pfile, fp, desc, len) unsigned long col; line_base = find_position (line_base, op, &line); col = op - line_base + 1; - cpp_warning_with_line (pfile, line, col, "no newline at end of file\n"); + cpp_warning_with_line (pfile, line, col, "no newline at end of file"); if (offset + 1 > len) { len += 1; @@ -1811,7 +1817,8 @@ _cpp_read_and_prescan (pfile, fp, desc, len) return op - buf; too_big: - cpp_error (pfile, "file is too large (>%lu bytes)\n", (unsigned long)offset); + cpp_notice (pfile, "%s is too large (>%lu bytes)", fp->ihash->name, + (unsigned long)offset); free (buf); return -1; |