diff options
author | dholland <dholland@NetBSD.org> | 2009-06-07 20:13:18 +0000 |
---|---|---|
committer | dholland <dholland@NetBSD.org> | 2009-06-07 20:13:18 +0000 |
commit | 9a33f5bfb221170e823efd3c33ab5d331baf7c74 (patch) | |
tree | 56cfd04dbcbacdc38273193be59800509d41bc7b /hack/hack.options.c | |
parent | b462731cbc1198051cd39ad2f95b1027e441067d (diff) | |
download | bsdgames-darwin-9a33f5bfb221170e823efd3c33ab5d331baf7c74.tar.gz bsdgames-darwin-9a33f5bfb221170e823efd3c33ab5d331baf7c74.tar.zst bsdgames-darwin-9a33f5bfb221170e823efd3c33ab5d331baf7c74.zip |
sprintf -> snprintf, plus some use of strlcpy/strlcat where appropriate
XXX: there's still one sprintf left which will take some hacking to expunge.
Diffstat (limited to 'hack/hack.options.c')
-rw-r--r-- | hack/hack.options.c | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/hack/hack.options.c b/hack/hack.options.c index b03454aa..e01a0d04 100644 --- a/hack/hack.options.c +++ b/hack/hack.options.c @@ -1,4 +1,4 @@ -/* $NetBSD: hack.options.c,v 1.8 2009/06/07 18:30:39 dholland Exp $ */ +/* $NetBSD: hack.options.c,v 1.9 2009/06/07 20:13:18 dholland Exp $ */ /* * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica, @@ -63,7 +63,7 @@ #include <sys/cdefs.h> #ifndef lint -__RCSID("$NetBSD: hack.options.c,v 1.8 2009/06/07 18:30:39 dholland Exp $"); +__RCSID("$NetBSD: hack.options.c,v 1.9 2009/06/07 20:13:18 dholland Exp $"); #endif /* not lint */ #include <stdlib.h> @@ -237,7 +237,8 @@ bad: int doset(void) { - char buf[BUFSZ]; + char buf[BUFSZ]; + size_t pos; pline("What options do you want to set? "); getlin(buf); @@ -245,22 +246,24 @@ doset(void) (void) strcpy(buf, "HACKOPTIONS="); (void) strcat(buf, flags.female ? "female," : "male,"); if (flags.standout) - (void) strcat(buf, "standout,"); + (void) strlcat(buf, "standout,", sizeof(buf)); if (flags.nonull) - (void) strcat(buf, "nonull,"); + (void) strlcat(buf, "nonull,", sizeof(buf)); if (flags.nonews) - (void) strcat(buf, "nonews,"); + (void) strlcat(buf, "nonews,", sizeof(buf)); if (flags.time) - (void) strcat(buf, "time,"); + (void) strlcat(buf, "time,", sizeof(buf)); if (flags.notombstone) - (void) strcat(buf, "notombstone,"); + (void) strlcat(buf, "notombstone,", sizeof(buf)); if (flags.no_rest_on_space) - (void) strcat(buf, "!rest_on_space,"); + (void) strlcat(buf, "!rest_on_space,", sizeof(buf)); if (flags.end_top != 5 || flags.end_around != 4 || flags.end_own) { - (void) sprintf(eos(buf), "endgame: %u topscores/%u around me", + pos = strlen(buf); + (void) snprintf(buf+pos, sizeof(buf)-pos, + "endgame: %u topscores/%u around me", flags.end_top, flags.end_around); if (flags.end_own) - (void) strcat(buf, "/own scores"); + (void) strlcat(buf, "/own scores", sizeof(buf)); } else { char *eop = eos(buf); if (*--eop == ',') |