Subject: lib/1155: lint(1) warnings in libcompat
To: None <gnats-admin@sun-lamp.pc.cs.cmu.edu>
From: Thorsten Lockert <tholo@SigmaSoft.COM>
List: netbsd-bugs
Date: 06/25/1995 00:05:08
>Number:         1155
>Category:       lib
>Synopsis:       lint(1) warnings in libcompat
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    lib-bug-people (Library Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Jun 25 00:05:04 1995
>Originator:     Thorsten Lockert
>Organization:
SigmaSoft, Th. Lockert
>Release:        June 23, 1995
>Environment:
System: NetBSD gandalf.sigmasoft.com 1.0A NetBSD 1.0A (GANDALF) #1: Sun May 7 21:49:27 PDT 1995 tholo@gandalf.sigmasoft.com:/usr/src/sys/arch/i386/compile/GANDALF i386


>Description:
	There are still some minor warnings flagged in libcompat by
	lint(1) after the compile time warnings has been taken care
	of.

>How-To-Repeat:
	Run lint(1) on it...

>Fix:
	Apply the following patches.  Note that one side-effect of them
	are that a global "char *re_errstr" is added and a duplicate of
	the function regerror() is removed.  The name of the global should
	perhaps be changed.

diff -cr libcompat.orig/4.3/lsearch.c libcompat/4.3/lsearch.c
*** libcompat.orig/4.3/lsearch.c	Sat Jun 24 19:58:54 1995
--- libcompat/4.3/lsearch.c	Sat Jun 24 20:02:01 1995
***************
*** 91,96 ****
  	 * manual.
  	 */
  	++*nelp;
! 	memcpy((void *)end, key, width);
  	return((void *)end);
  }
--- 91,96 ----
  	 * manual.
  	 */
  	++*nelp;
! 	(void) memcpy((void *)end, key, width);
  	return((void *)end);
  }
diff -cr libcompat.orig/4.3/regex.c libcompat/4.3/regex.c
*** libcompat.orig/4.3/regex.c	Sat Jun 24 19:58:54 1995
--- libcompat/4.3/regex.c	Sat Jun 24 20:14:58 1995
***************
*** 54,65 ****
  
  static regexp *re_regexp;
  static int re_goterr;
- static char *re_errstr;
  
  char *
  re_comp(s)
  	const char *s;
  {
  	if (s == NULL)
  		return (NULL);
  	if (re_regexp)
--- 54,66 ----
  
  static regexp *re_regexp;
  static int re_goterr;
  
  char *
  re_comp(s)
  	const char *s;
  {
+ 	extern char *re_errstr;
+ 
  	if (s == NULL)
  		return (NULL);
  	if (re_regexp)
***************
*** 67,72 ****
--- 68,74 ----
  	if (re_errstr)
  		free(re_errstr);
  	re_goterr = 0;
+ 	re_errstr = NULL;
  	re_regexp = regcomp(s);
  	return (re_goterr ? re_errstr : NULL);
  }
***************
*** 80,93 ****
  	re_goterr = 0;
  	rc = regexec(re_regexp, s);
  	return (re_goterr ? -1 : rc);
- }
- 
- void
- regerror(s)
- 	const char *s;
- {
- 	re_goterr = 1;
- 	if (re_errstr)
- 		free(re_errstr);
- 	re_errstr = strdup(s);
  }
--- 82,85 ----
diff -cr libcompat.orig/4.3/rexec.c libcompat/4.3/rexec.c
*** libcompat.orig/4.3/rexec.c	Sat Jun 24 19:58:54 1995
--- libcompat/4.3/rexec.c	Sat Jun 24 20:01:24 1995
***************
*** 83,89 ****
  	if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
  		if (errno == ECONNREFUSED && timo <= 16) {
  			(void) close(s);
! 			sleep(timo);
  			timo *= 2;
  			goto retry;
  		}
--- 83,89 ----
  	if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
  		if (errno == ECONNREFUSED && timo <= 16) {
  			(void) close(s);
! 			(void) sleep(timo);
  			timo *= 2;
  			goto retry;
  		}
***************
*** 102,108 ****
  			(void) close(s);
  			return (-1);
  		}
! 		listen(s2, 1);
  		sin2len = sizeof (sin2);
  		if (getsockname(s2, (struct sockaddr *)&sin2, &sin2len) < 0 ||
  		  sin2len != sizeof (sin2)) {
--- 102,112 ----
  			(void) close(s);
  			return (-1);
  		}
! 		if (listen(s2, 1) < 0) {
! 			perror("listen");
! 			(void) close(s2);
! 			goto bad;
! 		}
  		sin2len = sizeof (sin2);
  		if (getsockname(s2, (struct sockaddr *)&sin2, &sin2len) < 0 ||
  		  sin2len != sizeof (sin2)) {
***************
*** 115,121 ****
  		(void) write(s, num, strlen(num)+1);
  		{ int len = sizeof (from);
  		  s3 = accept(s2, (struct sockaddr *)&from, &len);
! 		  close(s2);
  		  if (s3 < 0) {
  			perror("accept");
  			port = 0;
--- 119,125 ----
  		(void) write(s, num, strlen(num)+1);
  		{ int len = sizeof (from);
  		  s3 = accept(s2, (struct sockaddr *)&from, &len);
! 		  (void) close(s2);
  		  if (s3 < 0) {
  			perror("accept");
  			port = 0;
diff -cr libcompat.orig/Makefile libcompat/Makefile
*** libcompat.orig/Makefile	Sat Jun 24 19:58:55 1995
--- libcompat/Makefile	Sat Jun 24 20:02:33 1995
***************
*** 1,6 ****
--- 1,7 ----
  #	$NetBSD: Makefile,v 1.14 1994/12/22 17:57:02 jtc Exp $
  
  LIB=	compat
+ LLIBS=
  CFLAGS+=-DLIBC_SCCS -DSYSLIBC_SCCS
  AINC=	-I${.CURDIR}/../libc/arch/${MACHINE_ARCH}
  .if defined(DESTDIR)
Only in libcompat: obj
diff -cr libcompat.orig/regexp/regerror.c libcompat/regexp/regerror.c
*** libcompat.orig/regexp/regerror.c	Sat Jun 24 19:58:54 1995
--- libcompat/regexp/regerror.c	Sat Jun 24 20:13:53 1995
***************
*** 3,22 ****
  #endif /* not lint */
  
  #include <regexp.h>
! #include <stdio.h>
  
  void
  regerror(s)
  const char *s;
  {
! #ifdef ERRAVAIL
! 	error("regexp: %s", s);
! #else
! /*
! 	fprintf(stderr, "regexp(3): %s\n", s);
! 	exit(1);
! */
! 	return;	  /* let std. egrep handle errors */
! #endif
! 	/* NOTREACHED */
  }
--- 3,17 ----
  #endif /* not lint */
  
  #include <regexp.h>
! #include <string.h>
! 
! char *re_errstr;
  
  void
  regerror(s)
  const char *s;
  {
! 	if (re_errstr)
! 		free(re_errstr);
! 	re_errstr = strdup(s);
  }
diff -cr libcompat.orig/regexp/regexp.c libcompat/regexp/regexp.c
*** libcompat.orig/regexp/regexp.c	Sat Jun 24 19:58:54 1995
--- libcompat/regexp/regexp.c	Sat Jun 24 20:40:39 1995
***************
*** 81,103 ****
   */
  
  /* definition	number	opnd?	meaning */
! #define	END	0	/* no	End of program. */
! #define	BOL	1	/* no	Match "" at beginning of line. */
! #define	EOL	2	/* no	Match "" at end of line. */
! #define	ANY	3	/* no	Match any one character. */
! #define	ANYOF	4	/* str	Match any character in this string. */
! #define	ANYBUT	5	/* str	Match any character not in this string. */
! #define	BRANCH	6	/* node	Match this alternative, or the next... */
! #define	BACK	7	/* no	Match "", "next" ptr points backward. */
! #define	EXACTLY	8	/* str	Match this string. */
! #define	NOTHING	9	/* no	Match empty string. */
! #define	STAR	10	/* node	Match this (simple) thing 0 or more times. */
! #define	PLUS	11	/* node	Match this (simple) thing 1 or more times. */
! #define	WORDA	12	/* no	Match "" at wordchar, where prev is nonword */
! #define	WORDZ	13	/* no	Match "" at nonwordchar, where prev is word */
! #define	OPEN	20	/* no	Mark this point in input as start of #n. */
  			/*	OPEN+1 is number 1, etc. */
! #define	CLOSE	30	/* no	Analogous to OPEN. */
  
  /*
   * Opcode notes:
--- 81,103 ----
   */
  
  /* definition	number	opnd?	meaning */
! #define	END	'\0'	/* no	End of program. */
! #define	BOL	'\1'	/* no	Match "" at beginning of line. */
! #define	EOL	'\2'	/* no	Match "" at end of line. */
! #define	ANY	'\3'	/* no	Match any one character. */
! #define	ANYOF	'\4'	/* str	Match any character in this string. */
! #define	ANYBUT	'\5'	/* str	Match any character not in this string. */
! #define	BRANCH	'\6'	/* node	Match this alternative, or the next... */
! #define	BACK	'\7'	/* no	Match "", "next" ptr points backward. */
! #define	EXACTLY	'\10'	/* str	Match this string. */
! #define	NOTHING	'\11'	/* no	Match empty string. */
! #define	STAR	'\12'	/* node	Match this (simple) thing 0 or more times. */
! #define	PLUS	'\13'	/* node	Match this (simple) thing 1 or more times. */
! #define	WORDA	'\14'	/* no	Match "" at wordchar, where prev is nonword */
! #define	WORDZ	'\15'	/* no	Match "" at nonwordchar, where prev is word */
! #define	OPEN	'\24'	/* no	Mark this point in input as start of #n. */
  			/*	OPEN+1 is number 1, etc. */
! #define	CLOSE	'\36'	/* no	Analogous to OPEN. */
  
  /*
   * Opcode notes:
***************
*** 313,319 ****
  			FAIL("too many ()");
  		parno = regnpar;
  		regnpar++;
! 		ret = regnode(OPEN+parno);
  	} else
  		ret = NULL;
  
--- 313,319 ----
  			FAIL("too many ()");
  		parno = regnpar;
  		regnpar++;
! 		ret = regnode((char) (OPEN+parno));
  	} else
  		ret = NULL;
  
***************
*** 340,346 ****
  	}
  
  	/* Make a closing node, and hook it on the end. */
! 	ender = regnode((paren) ? CLOSE+parno : END);	
  	regtail(ret, ender);
  
  	/* Hook the tails of the branches to the closing node. */
--- 340,346 ----
  	}
  
  	/* Make a closing node, and hook it on the end. */
! 	ender = regnode((char) (paren ? CLOSE+parno : END));
  	regtail(ret, ender);
  
  	/* Hook the tails of the branches to the closing node. */
***************
*** 513,519 ****
  						if (class > classend+1)
  							FAIL("invalid [] range");
  						for (; class <= classend; class++)
! 							regc(class);
  						regparse++;
  					}
  				} else
--- 513,519 ----
  						if (class > classend+1)
  							FAIL("invalid [] range");
  						for (; class <= classend; class++)
! 							regc((char) class);
  						regparse++;
  					}
  				} else
***************
*** 572,578 ****
  		 * On entry, the char at regparse[-1] is going to go
  		 * into the string, no matter what it is.  (It could be
  		 * following a \ if we are entered from the '\' case.)
! 		 * 
  		 * Basic idea is to pick up a good char in  ch  and
  		 * examine the next char.  If it's *+? then we twiddle.
  		 * If it's \ then we frozzle.  If it's other magic char
--- 572,578 ----
  		 * On entry, the char at regparse[-1] is going to go
  		 * into the string, no matter what it is.  (It could be
  		 * following a \ if we are entered from the '\' case.)
! 		 *
  		 * Basic idea is to pick up a good char in  ch  and
  		 * examine the next char.  If it's *+? then we twiddle.
  		 * If it's \ then we frozzle.  If it's other magic char
***************
*** 627,633 ****
  					default:
  						/* Backup point is \, scan							 * point is after it. */
  						regprev = regparse;
! 						regparse++; 
  						continue;	/* NOT break; */
  					}
  				}
--- 627,633 ----
  					default:
  						/* Backup point is \, scan							 * point is after it. */
  						regprev = regparse;
! 						regparse++;
  						continue;	/* NOT break; */
  					}
  				}
***************
*** 649,656 ****
--- 649,660 ----
   - regnode - emit a node
   */
  static char *			/* Location. */
+ #ifdef __STDC__
+ regnode(char op)
+ #else
  regnode(op)
  char op;
+ #endif
  {
  	register char *ret;
  	register char *ptr;
***************
*** 674,681 ****
--- 678,689 ----
   - regc - emit (if appropriate) a byte of code
   */
  static void
+ #ifdef __STDC__
+ regc(char b)
+ #else
  regc(b)
  char b;
+ #endif
  {
  	if (regcode != &regdummy)
  		*regcode++ = b;
***************
*** 689,697 ****
--- 697,709 ----
   * Means relocating the operand.
   */
  static void
+ #ifdef __STDC__
+ reginsert(char op, char *opnd)
+ #else
  reginsert(op, opnd)
  char op;
  char *opnd;
+ #endif
  {
  	register char *src;
  	register char *dst;
***************
*** 1175,1181 ****
  		next = regnext(s);
  		if (next == NULL)		/* Next ptr. */
  			printf("(0)");
! 		else 
  			printf("(%d)", (s-r->program)+(next-s));
  		s += 3;
  		if (op == ANYOF || op == ANYBUT || op == EXACTLY) {
--- 1187,1193 ----
  		next = regnext(s);
  		if (next == NULL)		/* Next ptr. */
  			printf("(0)");
! 		else
  			printf("(%d)", (s-r->program)+(next-s));
  		s += 3;
  		if (op == ANYOF || op == ANYBUT || op == EXACTLY) {
diff -cr libcompat.orig/regexp/regmagic.h libcompat/regexp/regmagic.h
*** libcompat.orig/regexp/regmagic.h	Sat Jun 24 19:58:54 1995
--- libcompat/regexp/regmagic.h	Sat Jun 24 20:17:37 1995
***************
*** 4,7 ****
   * The first byte of the regexp internal "program" is actually this magic
   * number; the start node begins in the second byte.
   */
! #define	MAGIC	0234
--- 4,7 ----
   * The first byte of the regexp internal "program" is actually this magic
   * number; the start node begins in the second byte.
   */
! #define	MAGIC	((char)0234)
>Audit-Trail:
>Unformatted: