GDB: Fix the overflow in addr/line_is_displayed()
[deliverable/binutils-gdb.git] / gdb / tui / tui-source.c
index 0728263b8c5f180fdc5b425473d80861774baf7a..1503cd4c63608f3db23965e36488280e5a4762da 100644 (file)
@@ -1,6 +1,6 @@
 /* TUI display source window.
 
-   Copyright (C) 1998-2019 Free Software Foundation, Inc.
+   Copyright (C) 1998-2020 Free Software Foundation, Inc.
 
    Contributed by Hewlett-Packard Company.
 
@@ -151,8 +151,6 @@ tui_source_window::do_scroll_vertical (int num_to_scroll)
       const std::vector<off_t> *offsets;
       if (g_source_cache.get_line_charpos (s, &offsets)
          && l.u.line_no > offsets->size ())
-       /* line = s->nlines - win_info->content_size + 1; */
-       /* elz: fix for dts 23398.  */
        l.u.line_no = start_line_or_addr.u.line_no;
       if (l.u.line_no <= 0)
        l.u.line_no = 1;
@@ -176,24 +174,23 @@ tui_source_window::location_matches_p (struct bp_location *loc, int line_no)
 bool
 tui_source_window::line_is_displayed (int line) const
 {
-  bool is_displayed = false;
-  int threshold = SCROLL_THRESHOLD;
-  int i = 0;
-  while (i < content.size () - threshold && !is_displayed)
+  if (content.size () < SCROLL_THRESHOLD)
+    return false;
+
+  for (size_t i = 0; i < content.size () - SCROLL_THRESHOLD; ++i)
     {
-      is_displayed
-       = (content[i].line_or_addr.loa == LOA_LINE
-          && content[i].line_or_addr.u.line_no == line);
-      i++;
+      if (content[i].line_or_addr.loa == LOA_LINE
+         && content[i].line_or_addr.u.line_no == line)
+       return true;
     }
 
-  return is_displayed;
+  return false;
 }
 
 void
 tui_source_window::maybe_update (struct frame_info *fi, symtab_and_line sal)
 {
-  int start_line = (sal.line - (viewport_height / 2)) + 1;
+  int start_line = (sal.line - ((height - 2) / 2)) + 1;
   if (start_line <= 0)
     start_line = 1;
 
This page took 0.023738 seconds and 4 git commands to generate.