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 --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;
-- 
1.8.5.3

Reply via email to