diff mbox

[committed] PR diagnostic/68899: fix read-beyond-buffer when printing very wide source lines

Message ID 1452920546-9202-1-git-send-email-dmalcolm@redhat.com
State New
Headers show

Commit Message

David Malcolm Jan. 16, 2016, 5:02 a.m. UTC
Our code for printing source code can apply an x-offset when printing very
wide source lines, which attempts to ensure that the caret will be printed
before line-wrapping occurs (it doesn't attempt to prevent line-wrapping,
but the old implementation didn't either).

The current implementation has a trivial bug in which the x-offset is applied
too early, leading to a read past the end of the source line buffer of
up to x-offset bytes.

Fixed thusly.

Successfully bootstrapped&regrtested on x86_64-pc-linux-gnu;
committed to trunk as r232465 as obvious.

gcc/ChangeLog:
	PR diagnostic/68899
	* diagnostic-show-locus.c (layout::print_source_line): Move x
        offset of line until after call to
        get_line_width_without_trailing_whitespace.
---
 gcc/diagnostic-show-locus.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
diff mbox

Patch

diff --git a/gcc/diagnostic-show-locus.c b/gcc/diagnostic-show-locus.c
index 3ef0052..e323254 100644
--- a/gcc/diagnostic-show-locus.c
+++ b/gcc/diagnostic-show-locus.c
@@ -524,14 +524,13 @@  layout::print_source_line (int row, line_bounds *lbounds_out)
   if (!line)
     return false;
 
-  line += m_x_offset;
-
   m_colorizer.set_normal_text ();
 
   /* We will stop printing the source line at any trailing
      whitespace.  */
   line_width = get_line_width_without_trailing_whitespace (line,
 							   line_width);
+  line += m_x_offset;
 
   pp_space (m_pp);
   int first_non_ws = INT_MAX;