From db58b57d39a6d63b43115c78fdede855db7a431d Mon Sep 17 00:00:00 2001 From: abs Date: Fri, 17 Mar 2006 23:22:59 +0000 Subject: if getpwuid() returns null, print out the uid rather than dereferencing Addresses Coverity CID 930 --- snake/snake/snake.c | 22 +++++++++++++++------- 1 file 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); } -- cgit v1.2.3-56-ge451