summaryrefslogtreecommitdiffstats
path: root/snake
diff options
context:
space:
mode:
authorabs <abs@NetBSD.org>2006-03-17 23:22:59 +0000
committerabs <abs@NetBSD.org>2006-03-17 23:22:59 +0000
commitdb58b57d39a6d63b43115c78fdede855db7a431d (patch)
tree6661aca82fdbbab441877fbb45c59cf54932fc99 /snake
parent3d3f1828613ad847852d189b6c406c539cc7a0d3 (diff)
downloadbsdgames-darwin-db58b57d39a6d63b43115c78fdede855db7a431d.tar.gz
bsdgames-darwin-db58b57d39a6d63b43115c78fdede855db7a431d.tar.zst
bsdgames-darwin-db58b57d39a6d63b43115c78fdede855db7a431d.zip
if getpwuid() returns null, print out the uid rather than dereferencing
Addresses Coverity CID 930
Diffstat (limited to 'snake')
-rw-r--r--snake/snake/snake.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/snake/snake/snake.c b/snake/snake/snake.c
index df95bfeb..ae004e94 100644
--- a/snake/snake/snake.c
+++ b/snake/snake/snake.c
@@ -1,4 +1,4 @@
-/* $NetBSD: snake.c,v 1.20 2004/02/08 00:33:31 jsm Exp $ */
+/* $NetBSD: snake.c,v 1.21 2006/03/17 23:22:59 abs Exp $ */
/*
* Copyright (c) 1980, 1993
@@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 1993\n\
#if 0
static char sccsid[] = "@(#)snake.c 8.2 (Berkeley) 1/7/94";
#else
-__RCSID("$NetBSD: snake.c,v 1.20 2004/02/08 00:33:31 jsm Exp $");
+__RCSID("$NetBSD: snake.c,v 1.21 2006/03/17 23:22:59 abs Exp $");
#endif
#endif /* not lint */
@@ -556,17 +556,25 @@ post(iscore, flag)
/* See if we have a new champ */
p = getpwuid(allbwho);
- if (p == NULL || score > allbscore) {
+ if (score > allbscore) {
lseek(rawscores, 0, SEEK_SET);
write(rawscores, &score, sizeof(short));
write(rawscores, &uid, sizeof(short));
- if (allbwho)
- printf("You beat %s's old record of $%d!\n",
- p->pw_name, allbscore);
+ if (allbwho) {
+ if (p)
+ printf("You beat %s's old record of $%d!\n",
+ p->pw_name, allbscore);
+ else
+ printf("You beat (%d)'s old record of $%d!\n",
+ (int)allbwho, allbscore);
+ }
else
printf("You set a new record!\n");
- } else
+ } else if (p)
printf("The highest is %s with $%d\n", p->pw_name, allbscore);
+ else
+ printf("The highest is (%d) with $%d\n", (int)allbwho,
+ allbscore);
lseek(rawscores, 0, SEEK_SET);
return (1);
}