bugs in /usr/ucb/indent

Jonathan Isaiah Kamens jik at athena.mit.edu
Thu Dec 15 10:01:49 AEST 1988


After the uproar raised recently in comp.unix.wizards about the
different indentation styles available to Unix C programmers, I
decided to try out the indent program mentioned by several people
during the discussion.  I got:

% indent ~/src/leave.c /tmp/leave.c
Segmentation Violation (core dumped).
%

Not pretty.  I was running this on an IBM RT workstation, so I tried
in on a VAX 750, and it worked.  Since the VAX tends to be just a bit
more tolerant of things like illegal array indices and such than the
RT does, I ran the code through saber on an RT.

The results were not pretty.  I've included below those fixes which I
had to make before indent would work properly on the RT.

If I may so, this code is very sloppy.  Whoever wrote it throws around
illegal array references liberally and seems to assume that the
machine will "do the right thing" instead of writing the code
correctly himself.

(Your line numbers may vary, of course.)

  Jonathan Kamens
  MIT Project Athena

--------begin patches to io.c from /usr/ucb/indent source code--------
*** /tmp/,RCSt1013186	Wed Dec 14 18:31:04 1988
--- io.c	Wed Dec 14 18:21:51 1988
***************
*** 258,264 ****
      *(e_com = s_com) = '\0';
      ps.ind_level = ps.i_l_follow;
      ps.paren_level = ps.p_l_follow;
!     paren_target = -ps.paren_indents[ps.paren_level - 1];
      return;
  };
  
--- 258,265 ----
      *(e_com = s_com) = '\0';
      ps.ind_level = ps.i_l_follow;
      ps.paren_level = ps.p_l_follow;
!     paren_target = (ps.paren_level > 0 ? -ps.paren_indents[ps.paren_level - 1]
! 		    : 0);
      return;
  };
  
***************
*** 330,343 ****
      }
      p = in_buffer;
      buf_ptr = p;
!     while ((*p++ = i = getc(f)) != EOF && i != '\n');
      if (i == EOF) {
! 	p[-1] = ' ';
  	*p++ = '\n';
  	had_eof = true;
      }
      buf_end = p;
!     if (p[-2] == '/' && p[-3] == '*') {
  	if (in_buffer[3] == 'I' && strncmp(in_buffer, "/**INDENT**", 11) == 0)
  	    fill_buffer();	/* flush indent error message */
  	else {
--- 331,348 ----
      }
      p = in_buffer;
      buf_ptr = p;
!     while ((i = getc(f)) != EOF && i != '\n')
! 	 *p++ = i;
!     if (i == '\n') *p++ = i;
      if (i == EOF) {
! 	if (p - in_buffer > 0)
! 	     p[-1] = ' ';
  	*p++ = '\n';
  	had_eof = true;
      }
      buf_end = p;
!     
!     if (p - in_buffer > 3) if (p[-2] == '/' && p[-3] == '*') {
  	if (in_buffer[3] == 'I' && strncmp(in_buffer, "/**INDENT**", 11) == 0)
  	    fill_buffer();	/* flush indent error message */
  	else {
--------end of patches to io.c--------



More information about the Comp.bugs.4bsd.ucb-fixes mailing list