Subject: lib/1098: multiple compile-time warnings in libcompat
To: None <gnats-admin@sun-lamp.cs.berkeley.edu>
From: Thorsten Lockert <tholo@SigmaSoft.COM>
List: netbsd-bugs
Date: 06/03/1995 14:50:07
>Number:         1098
>Category:       lib
>Synopsis:       there are multiple compile-time 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:   Sat Jun  3 14:50:03 1995
>Originator:     Thorsten Lockert
>Organization:
SigmaSoft, Th. Lockert
>Release:        May 28, 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 multiple compile-time warnings in libcompat if you
	compile it with -Wall -Wstrict-prototypes

	Also, the return type of ftime(3) in the manpage is wrong

>How-To-Repeat:
	Compile libcompat with -Wall -Wstrict-prototypes

>Fix:
	Apply the following patches:

diff -cr src/lib/libcompat.orig/4.1/ftime.c src/lib/libcompat/4.1/ftime.c
*** src/lib/libcompat.orig/4.1/ftime.c	Sat Jun  3 13:16:05 1995
--- src/lib/libcompat/4.1/ftime.c	Sat Jun  3 13:27:46 1995
***************
*** 36,41 ****
--- 36,42 ----
  #include <sys/time.h>
  #include <sys/timeb.h>
  
+ int
  ftime(tbp)
          struct timeb *tbp;
  {
diff -cr src/lib/libcompat.orig/4.3/cfree.c src/lib/libcompat/4.3/cfree.c
*** src/lib/libcompat.orig/4.3/cfree.c	Sat Jun  3 13:16:06 1995
--- src/lib/libcompat/4.3/cfree.c	Sat Jun  3 13:28:14 1995
***************
*** 35,40 ****
--- 35,42 ----
  static char sccsid[] = "@(#)cfree.c	8.1 (Berkeley) 6/4/93";
  #endif /* LIBC_SCCS and not lint */
  
+ #include <stdlib.h>
+ 
  void
  cfree(p)
  	void *p;
diff -cr src/lib/libcompat.orig/4.3/lsearch.c src/lib/libcompat/4.3/lsearch.c
*** src/lib/libcompat.orig/4.3/lsearch.c	Sat Jun  3 13:16:06 1995
--- src/lib/libcompat/4.3/lsearch.c	Sat Jun  3 14:07:31 1995
***************
*** 39,78 ****
  #endif /* LIBC_SCCS and not lint */
  
  #include <sys/types.h>
! #include <unistd.h>
  
! static char *linear_base();
  
! char *
  lsearch(key, base, nelp, width, compar)
! 	char *key, *base;
! 	u_int *nelp, width;
! 	int (*compar)();
  {
  	return(linear_base(key, base, nelp, width, compar, 1));
  }
  
! char *
  lfind(key, base, nelp, width, compar)
! 	char *key, *base;
! 	u_int *nelp, width;
! 	int (*compar)();
  {
  	return(linear_base(key, base, nelp, width, compar, 0));
  }
  
! static char *
  linear_base(key, base, nelp, width, compar, add_flag)
! 	char *key, *base;
! 	u_int *nelp, width;
! 	int (*compar)(), add_flag;
  {
! 	register char *element, *end;
  
! 	end = base + *nelp * width;
  	for (element = base; element < end; element += width)
  		if (!compar(element, key))		/* key found */
! 			return(element);
  
  	if (!add_flag)					/* key not found */
  		return(NULL);
--- 39,80 ----
  #endif /* LIBC_SCCS and not lint */
  
  #include <sys/types.h>
! #include <string.h>
! #include <search.h>
  
! static void *linear_base __P((const void *, const void *, size_t *, size_t,
! 				    int (*)(const void *, const void *), int));
  
! void *
  lsearch(key, base, nelp, width, compar)
! 	const void *key, *base;
! 	size_t *nelp, width;
! 	int (*compar) __P((const void *, const void *));
  {
  	return(linear_base(key, base, nelp, width, compar, 1));
  }
  
! void *
  lfind(key, base, nelp, width, compar)
! 	const void *key, *base;
! 	size_t *nelp, width;
! 	int (*compar) __P((const void *, const void *));
  {
  	return(linear_base(key, base, nelp, width, compar, 0));
  }
  
! static void *
  linear_base(key, base, nelp, width, compar, add_flag)
! 	const void *key, *base;
! 	size_t *nelp, width;
! 	int (*compar) __P((const void *, const void *)), add_flag;
  {
! 	register const char *element, *end;
  
! 	end = (const char *)base + *nelp * width;
  	for (element = base; element < end; element += width)
  		if (!compar(element, key))		/* key found */
! 			return((void *)element);
  
  	if (!add_flag)					/* key not found */
  		return(NULL);
***************
*** 87,92 ****
  	 * manual.
  	 */
  	++*nelp;
! 	bcopy(key, end, (int)width);
! 	return(end);
  }
--- 89,94 ----
  	 * manual.
  	 */
  	++*nelp;
! 	memcpy((void *)end, key, width);
! 	return((void *)end);
  }
diff -cr src/lib/libcompat.orig/4.3/regex.c src/lib/libcompat/4.3/regex.c
*** src/lib/libcompat.orig/4.3/regex.c	Sat Jun  3 13:16:06 1995
--- src/lib/libcompat/4.3/regex.c	Sat Jun  3 13:58:19 1995
***************
*** 51,56 ****
--- 51,57 ----
  #include <regexp.h>
  #include <string.h>
  #include <stdlib.h>
+ #include <unistd.h>
  
  static regexp *re_regexp;
  static int re_goterr;
***************
*** 58,64 ****
  
  char *
  re_comp(s)
! 	char *s;
  {
  	if (s == NULL)
  		return (NULL);
--- 59,65 ----
  
  char *
  re_comp(s)
! 	const char *s;
  {
  	if (s == NULL)
  		return (NULL);
***************
*** 73,79 ****
  
  int
  re_exec(s)
! 	char *s;
  {
  	int rc;
  
--- 74,80 ----
  
  int
  re_exec(s)
! 	const char *s;
  {
  	int rc;
  
diff -cr src/lib/libcompat.orig/4.3/rexec.c src/lib/libcompat/4.3/rexec.c
*** src/lib/libcompat.orig/4.3/rexec.c	Sat Jun  3 13:16:07 1995
--- src/lib/libcompat/4.3/rexec.c	Sat Jun  3 14:20:28 1995
***************
*** 44,64 ****
  #include <netdb.h>
  #include <string.h>
  #include <errno.h>
  
- extern	errno;
- char	*index();
  int	rexecoptions;
- char	*getpass(), *getlogin();
  
  rexec(ahost, rport, name, pass, cmd, fd2p)
  	char **ahost;
  	int rport;
  	char *name, *pass, *cmd;
  	int *fd2p;
  {
! 	struct sockaddr_in sin, sin2, from;
  	struct hostent *hp;
! 	u_short port;
  	int s, timo = 1, s3;
  	char c;
  
--- 44,65 ----
  #include <netdb.h>
  #include <string.h>
  #include <errno.h>
+ #include <unistd.h>
  
  int	rexecoptions;
  
+ void ruserpass __P((const char *, char **, char **));
+ 
+ int
  rexec(ahost, rport, name, pass, cmd, fd2p)
  	char **ahost;
  	int rport;
  	char *name, *pass, *cmd;
  	int *fd2p;
  {
! 	struct sockaddr_in sin1, sin2, from;
  	struct hostent *hp;
! 	u_short port = 0;
  	int s, timo = 1, s3;
  	char c;
  
***************
*** 75,84 ****
  		perror("rexec: socket");
  		return (-1);
  	}
! 	sin.sin_family = hp->h_addrtype;
! 	sin.sin_port = rport;
! 	bcopy(hp->h_addr, (caddr_t)&sin.sin_addr, hp->h_length);
! 	if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
  		if (errno == ECONNREFUSED && timo <= 16) {
  			(void) close(s);
  			sleep(timo);
--- 76,85 ----
  		perror("rexec: socket");
  		return (-1);
  	}
! 	sin1.sin_family = hp->h_addrtype;
! 	sin1.sin_port = rport;
! 	bcopy(hp->h_addr, (caddr_t)&sin1.sin_addr, hp->h_length);
! 	if (connect(s, (struct sockaddr *)&sin1, sizeof(sin1)) < 0) {
  		if (errno == ECONNREFUSED && timo <= 16) {
  			(void) close(s);
  			sleep(timo);
***************
*** 90,96 ****
  	}
  	if (fd2p == 0) {
  		(void) write(s, "", 1);
- 		port = 0;
  	} else {
  		char num[8];
  		int s2, sin2len;
--- 91,96 ----
Only in src/lib/libcompat: obj
diff -cr src/lib/libcompat.orig/regexp/regexp.c src/lib/libcompat/regexp/regexp.c
*** src/lib/libcompat.orig/regexp/regexp.c	Sat Jun  3 13:16:07 1995
--- src/lib/libcompat/regexp/regexp.c	Sat Jun  3 14:29:56 1995
***************
*** 175,192 ****
  #ifndef STATIC
  #define	STATIC	static
  #endif
! STATIC char *reg();
! STATIC char *regbranch();
! STATIC char *regpiece();
! STATIC char *regatom();
! STATIC char *regnode();
! STATIC char *regnext();
! STATIC void regc();
! STATIC void reginsert();
! STATIC void regtail();
! STATIC void regoptail();
  #ifdef STRCSPN
! STATIC int strcspn();
  #endif
  
  /*
--- 175,192 ----
  #ifndef STATIC
  #define	STATIC	static
  #endif
! STATIC char *reg __P((int, int *));
! STATIC char *regbranch __P((int *));
! STATIC char *regpiece __P((int *));
! STATIC char *regatom __P((int *));
! STATIC char *regnode __P((char));
! STATIC char *regnext __P((char *));
! STATIC void regc __P((char));
! STATIC void reginsert __P((char, char *));
! STATIC void regtail __P((char *, char *));
! STATIC void regoptail __P((char *, char *));
  #ifdef STRCSPN
! STATIC int strcspn __P((char *, char *));
  #endif
  
  /*
***************
*** 302,308 ****
  	register char *ret;
  	register char *br;
  	register char *ender;
! 	register int parno;
  	int flags;
  
  	*flagp = HASWIDTH;	/* Tentatively. */
--- 302,308 ----
  	register char *ret;
  	register char *br;
  	register char *ender;
! 	register int parno = 0;
  	int flags;
  
  	*flagp = HASWIDTH;	/* Tentatively. */
***************
*** 775,788 ****
  /*
   * Forwards.
   */
! STATIC int regtry();
! STATIC int regmatch();
! STATIC int regrepeat();
  
  #ifdef DEBUG
  int regnarrate = 0;
! void regdump();
! STATIC char *regprop();
  #endif
  
  /*
--- 775,788 ----
  /*
   * Forwards.
   */
! STATIC int regtry __P((const regexp *, const char *));
! STATIC int regmatch __P((char *));
! STATIC int regrepeat __P((char *));
  
  #ifdef DEBUG
  int regnarrate = 0;
! void regdump __P((regexp *));
! STATIC char *regprop __P((char *));
  #endif
  
  /*
***************
*** 794,800 ****
  register const char *string;
  {
  	register char *s;
- 	extern char *strchr();
  
  	/* Be paranoid... */
  	if (prog == NULL || string == NULL) {
--- 794,799 ----
***************
*** 852,865 ****
   */
  static int			/* 0 failure, 1 success */
  regtry(prog, string)
! regexp *prog;
! char *string;
  {
  	register int i;
  	register char **sp;
  	register char **ep;
  
! 	reginput = string;
  	regstartp = prog->startp;
  	regendp = prog->endp;
  
--- 851,864 ----
   */
  static int			/* 0 failure, 1 success */
  regtry(prog, string)
! const regexp *prog;
! const char *string;
  {
  	register int i;
  	register char **sp;
  	register char **ep;
  
! 	reginput = (char *)string;
  	regstartp = prog->startp;
  	regendp = prog->endp;
  
***************
*** 870,877 ****
  		*ep++ = NULL;
  	}
  	if (regmatch(prog->program + 1)) {
! 		prog->startp[0] = string;
! 		prog->endp[0] = reginput;
  		return(1);
  	} else
  		return(0);
--- 869,876 ----
  		*ep++ = NULL;
  	}
  	if (regmatch(prog->program + 1)) {
! 		((regexp *)prog)->startp[0] = (char *)string;
! 		((regexp *)prog)->endp[0] = reginput;
  		return(1);
  	} else
  		return(0);
***************
*** 893,899 ****
  {
  	register char *scan;	/* Current node. */
  	char *next;		/* Next node. */
- 	extern char *strchr();
  
  	scan = prog;
  #ifdef DEBUG
--- 892,897 ----
***************
*** 1156,1163 ****
  }
  
  #ifdef DEBUG
- 
- STATIC char *regprop();
  
  /*
   - regdump - dump a regexp onto stdout in vaguely comprehensible form
--- 1154,1159 ----
diff -cr src/lib/libcompat.orig/regexp/regsub.c src/lib/libcompat/regexp/regsub.c
*** src/lib/libcompat.orig/regexp/regsub.c	Sat Jun  3 13:16:08 1995
--- src/lib/libcompat/regexp/regsub.c	Sat Jun  3 13:53:01 1995
***************
*** 48,54 ****
  	register char c;
  	register int no;
  	register int len;
- 	extern char *strncpy();
  
  	if (prog == NULL || source == NULL || dest == NULL) {
  		regerror("NULL parm to regsub");
--- 48,53 ----
diff -cr src/lib/libcompat.orig/4.1/ftime.3 src/lib/libcompat/4.1/ftime.3
*** src/lib/libcompat.orig/4.1/ftime.3	Sat Jun  3 14:35:05 1995
--- src/lib/libcompat/4.1/ftime.3	Sat Jun  3 14:35:17 1995
***************
*** 40,46 ****
  .Sh SYNOPSIS
  .Fd #include <sys/types.h>
  .Fd #include <sys/timeb.h>
! .Ft struct timeb *
  .Fn ftime "struct timeb *tp"
  .Sh DESCRIPTION
  .Bf -symbolic
--- 40,46 ----
  .Sh SYNOPSIS
  .Fd #include <sys/types.h>
  .Fd #include <sys/timeb.h>
! .Ft int
  .Fn ftime "struct timeb *tp"
  .Sh DESCRIPTION
  .Bf -symbolic
>Audit-Trail:
>Unformatted: