]> git.cameronkatri.com Git - bsdgames-darwin.git/blobdiff - hack/hack.options.c
sprintf -> snprintf, plus some use of strlcpy/strlcat where appropriate
[bsdgames-darwin.git] / hack / hack.options.c
index 80168142186b0bf3e1a249f5207e49892386a3a2..e01a0d04451f62150c2e15bd3d110189d7b58306 100644 (file)
@@ -1,4 +1,4 @@
-/*     $NetBSD: hack.options.c,v 1.6 2003/04/02 18:36:39 jsm 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.6 2003/04/02 18:36:39 jsm Exp $");
+__RCSID("$NetBSD: hack.options.c,v 1.9 2009/06/07 20:13:18 dholland Exp $");
 #endif                         /* not lint */
 
 #include <stdlib.h>
@@ -72,7 +72,7 @@ __RCSID("$NetBSD: hack.options.c,v 1.6 2003/04/02 18:36:39 jsm Exp $");
 #include "extern.h"
 
 void
-initoptions()
+initoptions(void)
 {
        char           *opts;
 
@@ -89,9 +89,7 @@ initoptions()
 }
 
 void
-parseoptions(opts, from_env)
-       char           *opts;
-       boolean         from_env;
+parseoptions(char *opts, boolean from_env)
 {
        char           *op, *op2;
        unsigned        num;
@@ -210,7 +208,7 @@ bad:
                if (!strncmp(opts, "help", 4)) {
                        pline("%s%s%s",
                              "To set options use `HACKOPTIONS=\"<options>\"' in your environment, or ",
-                             "give the command 'o' followed by the line `<options>' while playing. ",
+                             "give the command 'O' followed by the line `<options>' while playing. ",
                              "Here <options> is a list of <option>s separated by commas.");
                        pline("%s%s%s",
                              "Simple (boolean) options are rest_on_space, news, time, ",
@@ -225,7 +223,7 @@ bad:
                        return;
                }
                pline("Bad option: %s.", opts);
-               pline("Type `o help<cr>' for help.");
+               pline("Type `O help<cr>' for help.");
                return;
        }
        puts("Bad syntax in HACKOPTIONS.");
@@ -237,9 +235,10 @@ bad:
 }
 
 int
-doset()
+doset(void)
 {
-       char            buf[BUFSZ];
+       char buf[BUFSZ];
+       size_t pos;
 
        pline("What options do you want to set? ");
        getlin(buf);
@@ -247,22 +246,24 @@ doset()
                (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 == ',')