Skip to content

Commit

Permalink
Add a few more GCC warnings on GCC >= 2 for ".devel" builds.
Browse files Browse the repository at this point in the history
From Neil T. Spring: fixes for many of those warnings:

	addrtoname.c, configure.in: Linux needs netinet/ether.h for
	ether_ntohost

	print-*.c: change char *foo = "bar" to const char *foo = "bar"
	to appease -Wwrite-strings; should affect no run-time behavior.

	print-*.c: make some variables unsigned.

	print-bgp.c: plen ('prefix len') is unsigned, no reason to
	validate by comparing to zero.

	print-cnfp.c, print-rx.c: use intoa, provided by addrtoname,
	instead of inet_ntoa.

	print-domain.c: unsigned int l; (l=foo()) < 0 is guaranteed to
	be false, so check for (u_int)-1, which represents failure,
	explicitly.

	print-isakmp.c: complete initialization of attrmap objects.

	print-lwres.c: "if(x); print foo;" seemed much more likely to be
	intended to be "if(x) { print foo; }".

	print-smb.c: complete initialization of some structures.

In addition, add some fixes for the signed vs. unsigned comparison
warnings:

	extract.h: cast the result of the byte-extraction-and-combining,
	as, at least for the 16-bit version, C's integral promotions
	will turn "u_int16_t" into "int" if there are other "int"s
	nearby.

	print-*.c: make some more variables unsigned, or add casts to an
	unsigned type of signed values known not to be negative, or add
	casts to "int" of unsigned values known to fit in an "int", and
	make other changes needed to handle the aforementioned variables
	now being unsigned.

	print-isakmp.c: clean up the handling of error/status indicators
	in notify messages.

	print-ppp.c: get rid of a check that an unsigned quantity is >=
	0.

	print-radius.c: clean up some of the bounds checking.

	print-smb.c: extract the word count into a "u_int" to avoid the
	aforementioned problems with C's integral promotions.

	print-snmp.c: change a check that an unsigned variable is >= 0
	to a check that it's != 0.

Also, fix some formats to use "%u" rather than "%d" for unsigned
quantities.
  • Loading branch information
yuguy committed Sep 5, 2002
1 parent 28b5392 commit edb0e92
Show file tree
Hide file tree
Showing 41 changed files with 323 additions and 265 deletions.
1 change: 1 addition & 0 deletions CREDITS
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ Additional people who have contributed patches:
Motonori Shindo <mshindo@mshindo.net>
Nathan J. Williams <nathanw@MIT.EDU>
Nathaniel Couper-Noles <Nathaniel@isi1.tccisi.com>
Neil T. Spring <bluehal@users.sourceforge.net>
Niels Provos <provos@openbsd.org>
Nickolai Zeldovich <kolya@MIT.EDU>
Olaf Kirch <okir@caldera.de>
Expand Down
7 changes: 4 additions & 3 deletions aclocal.m4
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
dnl @(#) $Header: /tcpdump/master/tcpdump/aclocal.m4,v 1.87 2002-08-04 21:20:29 guy Exp $ (LBL)
dnl @(#) $Header: /tcpdump/master/tcpdump/aclocal.m4,v 1.88 2002-09-05 00:00:07 guy Exp $ (LBL)
dnl
dnl Copyright (c) 1995, 1996, 1997, 1998
dnl The Regents of the University of California. All rights reserved.
Expand Down Expand Up @@ -594,7 +594,8 @@ EOF
dnl
dnl If using gcc and the file .devel exists:
dnl Compile with -g (if supported) and -Wall
dnl If using gcc 2, do extra prototype checking
dnl If using gcc 2 or later, do extra prototype checking and some other
dnl checks
dnl If an os prototype include exists, symlink os-proto.h to it
dnl
dnl usage:
Expand All @@ -620,7 +621,7 @@ AC_DEFUN(AC_LBL_DEVEL,
fi
$1="$$1 -Wall"
if test $ac_cv_lbl_gcc_vers -gt 1 ; then
$1="$$1 -Wmissing-prototypes -Wstrict-prototypes"
$1="$$1 -Wmissing-prototypes -Wstrict-prototypes -Wwrite-strings -W -Wno-unused"
fi
fi
else
Expand Down
5 changes: 4 additions & 1 deletion addrtoname.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/
#ifndef lint
static const char rcsid[] =
"@(#) $Header: /tcpdump/master/tcpdump/addrtoname.c,v 1.92 2002-08-07 13:53:21 risso Exp $ (LBL)";
"@(#) $Header: /tcpdump/master/tcpdump/addrtoname.c,v 1.93 2002-09-05 00:00:08 guy Exp $ (LBL)";
#endif

#ifdef HAVE_CONFIG_H
Expand All @@ -39,6 +39,9 @@ struct rtentry; /* declarations in <net/if.h> */
#include <net/if.h> /* for "struct ifnet" in "struct arpcom" on Solaris */
#include <netinet/if_ether.h>
#endif /* HAVE_NETINET_IF_ETHER_H */
#ifdef HAVE_NETINET_ETHER_H
#include <netinet/ether.h> /* ether_ntohost on linux */
#endif /* HAVE_NETINET_ETHER_H */
#endif /* USE_ETHER_NTOHOST */

#include <pcap.h>
Expand Down
3 changes: 3 additions & 0 deletions config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@
/* Define if you have the <netdnet/dnetdb.h> header file. */
#undef HAVE_NETDNET_DNETDB_H

/* Define if you have the <netinet/ether.h> header file. */
#undef HAVE_NETINET_ETHER_H

/* Define if you have the <netinet/if_ether.h> header file. */
#undef HAVE_NETINET_IF_ETHER_H

Expand Down
6 changes: 3 additions & 3 deletions configure
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! /bin/sh

# From configure.in Revision: 1.155
# From configure.in Revision: 1.156



Expand Down Expand Up @@ -1268,7 +1268,7 @@ else
fi
echo "$ac_t""$CPP" 1>&6

for ac_hdr in fcntl.h rpc/rpcent.h netinet/if_ether.h netdnet/dnetdb.h
for ac_hdr in fcntl.h rpc/rpcent.h netinet/if_ether.h netdnet/dnetdb.h netinet/ether.h
do
ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
Expand Down Expand Up @@ -4291,7 +4291,7 @@ rm -f os-proto.h
fi
V_CCOPT="$V_CCOPT -Wall"
if test $ac_cv_lbl_gcc_vers -gt 1 ; then
V_CCOPT="$V_CCOPT -Wmissing-prototypes -Wstrict-prototypes"
V_CCOPT="$V_CCOPT -Wmissing-prototypes -Wstrict-prototypes -Wwrite-strings -W -Wno-unused"
fi
fi
else
Expand Down
6 changes: 3 additions & 3 deletions configure.in
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
dnl @(#) $Header: /tcpdump/master/tcpdump/configure.in,v 1.155 2002-08-03 22:37:01 guy Exp $ (LBL)
dnl @(#) $Header: /tcpdump/master/tcpdump/configure.in,v 1.156 2002-09-05 00:00:08 guy Exp $ (LBL)
dnl
dnl Copyright (c) 1994, 1995, 1996, 1997
dnl The Regents of the University of California. All rights reserved.
dnl
dnl Process this file with autoconf to produce a configure script.
dnl

AC_REVISION($Revision: 1.155 $)
AC_REVISION($Revision: 1.156 $)
AC_PREREQ(2.13)
AC_INIT(tcpdump.c)

Expand All @@ -16,7 +16,7 @@ AC_LBL_C_INIT(V_CCOPT, V_INCLS)
AC_LBL_C_INLINE
AC_C___ATTRIBUTE__

AC_CHECK_HEADERS(fcntl.h rpc/rpcent.h netinet/if_ether.h netdnet/dnetdb.h)
AC_CHECK_HEADERS(fcntl.h rpc/rpcent.h netinet/if_ether.h netdnet/dnetdb.h netinet/ether.h)
AC_HEADER_TIME

case "$host_os" in
Expand Down
32 changes: 16 additions & 16 deletions extract.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* @(#) $Header: /tcpdump/master/tcpdump/extract.h,v 1.17 2001-09-17 21:57:52 fenner Exp $ (LBL)
* @(#) $Header: /tcpdump/master/tcpdump/extract.h,v 1.18 2002-09-05 00:00:09 guy Exp $ (LBL)
*/

/* Network to host order macros */

#ifdef LBL_ALIGN
#define EXTRACT_16BITS(p) \
((u_int16_t)*((const u_int8_t *)(p) + 0) << 8 | \
(u_int16_t)*((const u_int8_t *)(p) + 1))
((u_int16_t)((u_int16_t)*((const u_int8_t *)(p) + 0) << 8 | \
(u_int16_t)*((const u_int8_t *)(p) + 1)))
#define EXTRACT_32BITS(p) \
((u_int32_t)*((const u_int8_t *)(p) + 0) << 24 | \
(u_int32_t)*((const u_int8_t *)(p) + 1) << 16 | \
(u_int32_t)*((const u_int8_t *)(p) + 2) << 8 | \
(u_int32_t)*((const u_int8_t *)(p) + 3))
((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 0) << 24 | \
(u_int32_t)*((const u_int8_t *)(p) + 1) << 16 | \
(u_int32_t)*((const u_int8_t *)(p) + 2) << 8 | \
(u_int32_t)*((const u_int8_t *)(p) + 3)))
#else
#define EXTRACT_16BITS(p) \
((u_int16_t)ntohs(*(const u_int16_t *)(p)))
Expand All @@ -40,18 +40,18 @@
#endif

#define EXTRACT_24BITS(p) \
((u_int32_t)*((const u_int8_t *)(p) + 0) << 16 | \
(u_int32_t)*((const u_int8_t *)(p) + 1) << 8 | \
(u_int32_t)*((const u_int8_t *)(p) + 2))
((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 0) << 16 | \
(u_int32_t)*((const u_int8_t *)(p) + 1) << 8 | \
(u_int32_t)*((const u_int8_t *)(p) + 2)))

/* Little endian protocol host order macros */

#define EXTRACT_LE_8BITS(p) (*(p))
#define EXTRACT_LE_16BITS(p) \
((u_int16_t)*((const u_int8_t *)(p) + 1) << 8 | \
(u_int16_t)*((const u_int8_t *)(p) + 0))
((u_int16_t)((u_int16_t)*((const u_int8_t *)(p) + 1) << 8 | \
(u_int16_t)*((const u_int8_t *)(p) + 0)))
#define EXTRACT_LE_32BITS(p) \
((u_int32_t)*((const u_int8_t *)(p) + 3) << 24 | \
(u_int32_t)*((const u_int8_t *)(p) + 2) << 16 | \
(u_int32_t)*((const u_int8_t *)(p) + 1) << 8 | \
(u_int32_t)*((const u_int8_t *)(p) + 0))
((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 3) << 24 | \
(u_int32_t)*((const u_int8_t *)(p) + 2) << 16 | \
(u_int32_t)*((const u_int8_t *)(p) + 1) << 8 | \
(u_int32_t)*((const u_int8_t *)(p) + 0)))
4 changes: 2 additions & 2 deletions print-802_11.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#ifndef lint
static const char rcsid[] =
"@(#) $Header: /tcpdump/master/tcpdump/print-802_11.c,v 1.9 2002-08-01 08:52:59 risso Exp $ (LBL)";
"@(#) $Header: /tcpdump/master/tcpdump/print-802_11.c,v 1.10 2002-09-05 00:00:09 guy Exp $ (LBL)";
#endif

#ifdef HAVE_CONFIG_H
Expand All @@ -46,7 +46,7 @@ static const char rcsid[] =
#define PRINT_RATES(p) \
do { \
int z; \
char *sep = " ["; \
const char *sep = " ["; \
for (z = 0; z < p.rates.length ; z++) { \
printf("%s%2.1f", sep, (.5 * (p.rates.rate[z] & 0x7f))); \
sep = " "; \
Expand Down
4 changes: 2 additions & 2 deletions print-ascii.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

#ifndef lint
static const char rcsid[] =
"@(#) $Header: /tcpdump/master/tcpdump/print-ascii.c,v 1.9 2002-08-01 08:53:00 risso Exp $";
"@(#) $Header: /tcpdump/master/tcpdump/print-ascii.c,v 1.10 2002-09-05 00:00:10 guy Exp $";
#endif
#include <tcpdump-stdinc.h>
#include <stdio.h>
Expand All @@ -65,7 +65,7 @@ ascii_print_with_offset(register const u_char *cp, register u_int length,
register int nshorts;
char hexstuff[HEXDUMP_SHORTS_PER_LINE*HEXDUMP_HEXSTUFF_PER_SHORT+1], *hsp;
char asciistuff[ASCII_LINELENGTH+1], *asp;
int maxlength = (Aflag ? ASCII_LINELENGTH : HEXDUMP_SHORTS_PER_LINE);
u_int maxlength = (Aflag ? ASCII_LINELENGTH : HEXDUMP_SHORTS_PER_LINE);

nshorts = length / sizeof(u_short);
i = 0;
Expand Down
8 changes: 4 additions & 4 deletions print-bgp.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

#ifndef lint
static const char rcsid[] =
"@(#) $Header: /tcpdump/master/tcpdump/print-bgp.c,v 1.49 2002-08-25 18:25:57 hannes Exp $";
"@(#) $Header: /tcpdump/master/tcpdump/print-bgp.c,v 1.50 2002-09-05 00:00:10 guy Exp $";
#endif

#include <tcpdump-stdinc.h>
Expand Down Expand Up @@ -380,7 +380,7 @@ decode_prefix4(const u_char *pptr, char *buf, u_int buflen)
u_int plen;

plen = pptr[0];
if (plen < 0 || 32 < plen)
if (32 < plen)
return -1;

memset(&addr, 0, sizeof(addr));
Expand Down Expand Up @@ -411,7 +411,7 @@ decode_labeled_prefix4(const u_char *pptr, char *buf, u_int buflen)

plen-=24; /* adjust prefixlen - labellength */

if (plen < 0 || 32 < plen)
if (32 < plen)
return -1;

memset(&addr, 0, sizeof(addr));
Expand Down Expand Up @@ -478,7 +478,7 @@ decode_labeled_vpn_prefix4(const u_char *pptr, char *buf, u_int buflen)

plen-=(24+64); /* adjust prefixlen - labellength - RD len*/

if (plen < 0 || 32 < plen)
if (32 < plen)
return -1;

memset(&addr, 0, sizeof(addr));
Expand Down
10 changes: 6 additions & 4 deletions print-cnfp.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

#ifndef lint
static const char rcsid[] =
"@(#) $Header: /tcpdump/master/tcpdump/print-cnfp.c,v 1.9 2002-08-01 08:53:03 risso Exp $";
"@(#) $Header: /tcpdump/master/tcpdump/print-cnfp.c,v 1.10 2002-09-05 00:00:10 guy Exp $";
#endif

#ifdef HAVE_CONFIG_H
Expand All @@ -48,6 +48,8 @@ static const char rcsid[] =

#include "interface.h"

#include "addrtoname.h"

#include "tcp.h"

struct nfhdr {
Expand Down Expand Up @@ -129,7 +131,7 @@ cnfp_print(const u_char *cp, u_int len, const u_char *bp)
snprintf(asbuf, sizeof(asbuf), ":%u",
(unsigned)(ntohl(nr->asses) >> 16) & 0xffff);
}
printf("\n %s%s%s:%u ", inet_ntoa(nr->src_ina), buf, asbuf,
printf("\n %s%s%s:%u ", intoa(nr->src_ina.s_addr), buf, asbuf,
(unsigned)ntohl(nr->ports) >> 16);

if (ver == 5 || ver ==6) {
Expand All @@ -138,10 +140,10 @@ cnfp_print(const u_char *cp, u_int len, const u_char *bp)
snprintf(asbuf, sizeof(asbuf), ":%u",
(unsigned)ntohl(nr->asses) & 0xffff);
}
printf("> %s%s%s:%u ", inet_ntoa(nr->dst_ina), buf, asbuf,
printf("> %s%s%s:%u ", intoa(nr->dst_ina.s_addr), buf, asbuf,
(unsigned)ntohl(nr->ports) & 0xffff);

printf(">> %s\n ", inet_ntoa(nr->nhop_ina));
printf(">> %s\n ", intoa(nr->nhop_ina.s_addr));

pent = getprotobynumber((ntohl(nr->proto_tos) >> 8) & 0xff);
if (!pent || nflag)
Expand Down
8 changes: 4 additions & 4 deletions print-domain.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#ifndef lint
static const char rcsid[] =
"@(#) $Header: /tcpdump/master/tcpdump/print-domain.c,v 1.79 2002-08-01 08:53:04 risso Exp $ (LBL)";
"@(#) $Header: /tcpdump/master/tcpdump/print-domain.c,v 1.80 2002-09-05 00:00:11 guy Exp $ (LBL)";
#endif

#ifdef HAVE_CONFIG_H
Expand Down Expand Up @@ -152,7 +152,7 @@ ns_nprint(register const u_char *cp, register const u_char *bp)
int elt;
int data_size = snapend - bp;

if ((l = labellen(cp)) < 0)
if ((l = labellen(cp)) == (u_int)-1)
return(NULL);
if (!TTEST2(*cp, 1))
return(NULL);
Expand All @@ -172,7 +172,7 @@ ns_nprint(register const u_char *cp, register const u_char *bp)
if (!TTEST2(*cp, 1))
return(NULL);
cp = bp + (((i << 8) | *cp) & 0x3fff);
if ((l = labellen(cp)) < 0)
if ((l = labellen(cp)) == (u_int)-1)
return(NULL);
if (!TTEST2(*cp, 1))
return(NULL);
Expand Down Expand Up @@ -211,7 +211,7 @@ ns_nprint(register const u_char *cp, register const u_char *bp)
cp += l;
chars_processed += l;
putchar('.');
if ((l = labellen(cp)) < 0)
if ((l = labellen(cp)) == (u_int)-1)
return(NULL);
if (!TTEST2(*cp, 1))
return(NULL);
Expand Down
5 changes: 3 additions & 2 deletions print-dvmrp.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#ifndef lint
static const char rcsid[] =
"@(#) $Header: /tcpdump/master/tcpdump/print-dvmrp.c,v 1.22 2002-08-01 08:53:05 risso Exp $ (LBL)";
"@(#) $Header: /tcpdump/master/tcpdump/print-dvmrp.c,v 1.23 2002-09-05 00:00:11 guy Exp $ (LBL)";
#endif

#ifdef HAVE_CONFIG_H
Expand Down Expand Up @@ -154,7 +154,8 @@ print_report(register const u_char *bp, register const u_char *ep,
register u_int len)
{
register u_int32_t mask, origin;
register int metric, i, width, done;
register int metric, done;
register u_int i, width;

while (len > 0) {
if (len < 3) {
Expand Down
4 changes: 2 additions & 2 deletions print-egp.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#ifndef lint
static const char rcsid[] =
"@(#) $Header: /tcpdump/master/tcpdump/print-egp.c,v 1.30 2002-08-01 08:53:05 risso Exp $ (LBL)";
"@(#) $Header: /tcpdump/master/tcpdump/print-egp.c,v 1.31 2002-09-05 00:00:12 guy Exp $ (LBL)";
#endif

#ifdef HAVE_CONFIG_H
Expand Down Expand Up @@ -142,7 +142,7 @@ egpnrprint(register const struct egp_packet *egp, register u_int length)
register u_int netlen;
int gateways, distances, networks;
int t_gateways;
char *comma;
const char *comma;

addr = egp->egp_sourcenet;
if (IN_CLASSA(addr)) {
Expand Down
4 changes: 2 additions & 2 deletions print-esp.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

#ifndef lint
static const char rcsid[] =
"@(#) $Header: /tcpdump/master/tcpdump/print-esp.c,v 1.28 2002-08-01 08:53:05 risso Exp $ (LBL)";
"@(#) $Header: /tcpdump/master/tcpdump/print-esp.c,v 1.29 2002-09-05 00:00:12 guy Exp $ (LBL)";
#endif

#ifdef HAVE_CONFIG_H
Expand Down Expand Up @@ -73,7 +73,7 @@ enum cipher { NONE,


struct esp_algorithm {
char *name;
const char *name;
enum cipher algo;
int ivlen;
int authlen;
Expand Down
Loading

0 comments on commit edb0e92

Please sign in to comment.