aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/hexdump
diff options
context:
space:
mode:
authorJohan Karlsson <johan@FreeBSD.org>2004-07-22 13:14:42 +0000
committerJohan Karlsson <johan@FreeBSD.org>2004-07-22 13:14:42 +0000
commitaae01d2439166bb4eec5d1c06fd1e09b18309c0f (patch)
treedc9bf06dc37064adf55d14022440d375ab9479bc /usr.bin/hexdump
parent19a7439eddfc8dcf8377ba443567803bf3cdc608 (diff)
downloadsrc-aae01d2439166bb4eec5d1c06fd1e09b18309c0f.tar.gz
src-aae01d2439166bb4eec5d1c06fd1e09b18309c0f.zip
display.c:
- 'savech' is only used if it is set a few lines above where it is used, initialize it to silence warning. - 'length' is either -1 or greater than 0, hence it is safe to cast it to unsigned when comparing it here. odsyntax.c: - 'p' is assigned either (*argvp)[0] or (*argvp)[1] which both are char *. 'num' and 'end' are assigned values based on 'p'. Hence use char * instead of unsigned char * for these variables. '&end' as the second argument to strtoll does not need to be casted to char** any more. This solves a 'dereferencing type-punned pointer will break strict-aliasing rules' warning when compiling with -O2. parse.c: - 'prec' is only used when sokay == USEPREC and sokay = USEPREC when 'prec' is assigned. Hence 'prec' is not used uninitialized, initialize it to silence warning. - The code involving 'nextpr' is hard to follow, but I belive 'nextpr' will not be used unless it is initialized. Anyway, IF 'nextpr' is used uninitialized it is better to get a consistant error (seg fault, when dereferencing a NULL pointer) than potentially accessing some random memory. The above changes makes hexdump WARNS=6 clean even when compiled with -O2. Hence bump WARNS to keep it clean. Tested by: CFLAGS='-O2 -pipe' make universe
Notes
Notes: svn path=/head/; revision=132541
Diffstat (limited to 'usr.bin/hexdump')
-rw-r--r--usr.bin/hexdump/Makefile1
-rw-r--r--usr.bin/hexdump/display.c3
-rw-r--r--usr.bin/hexdump/odsyntax.c4
-rw-r--r--usr.bin/hexdump/parse.c3
4 files changed, 8 insertions, 3 deletions
diff --git a/usr.bin/hexdump/Makefile b/usr.bin/hexdump/Makefile
index 4cd3cc5dc62f..3252fc9af147 100644
--- a/usr.bin/hexdump/Makefile
+++ b/usr.bin/hexdump/Makefile
@@ -7,5 +7,6 @@ MAN= hexdump.1 od.1
MLINKS= hexdump.1 hd.1
LINKS= ${BINDIR}/hexdump ${BINDIR}/od
LINKS+= ${BINDIR}/hexdump ${BINDIR}/hd
+WARNS?= 6
.include <bsd.prog.mk>
diff --git a/usr.bin/hexdump/display.c b/usr.bin/hexdump/display.c
index c9ba892bbb24..0887f05deb2f 100644
--- a/usr.bin/hexdump/display.c
+++ b/usr.bin/hexdump/display.c
@@ -68,6 +68,7 @@ display(void)
off_t saveaddress;
u_char savech, *savebp;
+ savech = 0;
while ((bp = get()))
for (fs = fshead, savebp = bp, saveaddress = address; fs;
fs = fs->nextfs, bp = savebp, address = saveaddress)
@@ -318,7 +319,7 @@ peek(u_char *buf, size_t nbytes)
size_t n, nread;
int c;
- if (length != -1 && nbytes > length)
+ if (length != -1 && nbytes > (unsigned int)length)
nbytes = length;
nread = 0;
while (nread < nbytes && (c = getchar()) != EOF) {
diff --git a/usr.bin/hexdump/odsyntax.c b/usr.bin/hexdump/odsyntax.c
index 19684bffb635..e0f9283bbc22 100644
--- a/usr.bin/hexdump/odsyntax.c
+++ b/usr.bin/hexdump/odsyntax.c
@@ -193,7 +193,7 @@ odusage(void)
static void
odoffset(int argc, char ***argvp)
{
- unsigned char *p, *num, *end;
+ char *p, *num, *end;
int base;
/*
@@ -246,7 +246,7 @@ odoffset(int argc, char ***argvp)
base = 10;
}
- skip = strtoll(num, (char **)&end, base ? base : 8);
+ skip = strtoll(num, &end, base ? base : 8);
/* if end isn't the same as p, we got a non-octal digit */
if (end != p) {
diff --git a/usr.bin/hexdump/parse.c b/usr.bin/hexdump/parse.c
index 7b7f8e777aff..1231a1519ea5 100644
--- a/usr.bin/hexdump/parse.c
+++ b/usr.bin/hexdump/parse.c
@@ -214,6 +214,9 @@ rewrite(FS *fs)
char savech, cs[3];
int nconv, prec;
+ nextpr = NULL;
+ prec = 0;
+
for (fu = fs->nextfu; fu; fu = fu->nextfu) {
/*
* Break each format unit into print units; each conversion