This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: sched-vis: prevent visual_tbl overflow


On Dec  5, 2000, Richard Henderson <rth@redhat.com> wrote:

> On Tue, Dec 05, 2000 at 07:49:20PM -0200, Alexandre Oliva wrote:
>> +  sprintf (visual_tbl + strlen (visual_tbl), "%s", prefix);

> Please don't use sprintf in place of strcpy.

Here's a revised version, that also gets us rid of a warning about
signed x unsigned comparison.  Ok to install?

Index: gcc/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	* sched-vis.c (visual_tbl_line_length): New variable.
	(get_visual_tbl_length): Set it.
	(visualize_stall_cycles): Don't let stalls overrun
	visual_tbl_line_length.

Index: gcc/sched-vis.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/sched-vis.c,v
retrieving revision 1.2
diff -u -p -r1.2 sched-vis.c
--- gcc/sched-vis.c 2000/12/05 16:51:13 1.2
+++ gcc/sched-vis.c 2000/12/05 22:34:21
@@ -82,6 +82,7 @@ insn_print_units (insn)
 #define MAX_VISUAL_LINES 100
 #define INSN_LEN 30
 int n_visual_lines;
+static unsigned visual_tbl_line_length;
 char *visual_tbl;
 int n_vis_no_unit;
 rtx vis_no_unit[10];
@@ -133,6 +134,8 @@ get_visual_tbl_length ()
   n += n1;
   n += strlen ("\n") + 2;
 
+  visual_tbl_line_length = n;
+
   /* Compute length of visualization string.  */
   return (MAX_VISUAL_LINES * n);
 }
@@ -897,6 +900,9 @@ visualize_stall_cycles (stalls)
      int stalls;
 {
   int i;
+  const char *prefix = ";;       ";
+  const char *suffix = "\n";
+  char *p;
 
   /* If no more room, split table into two.  */
   if (n_visual_lines >= MAX_VISUAL_LINES)
@@ -907,10 +913,21 @@ visualize_stall_cycles (stalls)
 
   n_visual_lines++;
 
-  sprintf (visual_tbl + strlen (visual_tbl), ";;       ");
-  for (i = 0; i < stalls; i++)
-    sprintf (visual_tbl + strlen (visual_tbl), ".");
-  sprintf (visual_tbl + strlen (visual_tbl), "\n");
+  p = visual_tbl + strlen (visual_tbl);
+  strcpy (p, prefix);
+  p += strlen (prefix);
+
+  if ((unsigned)stalls >
+      visual_tbl_line_length - strlen (prefix) - strlen (suffix))
+    {
+      suffix = "[...]\n";
+      stalls = visual_tbl_line_length - strlen (prefix) - strlen (suffix);
+    }
+
+  memset (p, '.', stalls);
+  p += stalls;
+
+  strcpy (p, suffix);
 }
 
 /* Allocate data used for visualization during scheduling.  */

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                  aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist    *Please* write to mailing lists, not to me

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]