summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--games/hack/hack.main.c15
-rw-r--r--games/hack/hack.options.c1
-rw-r--r--games/hack/hack.shk.c3
-rw-r--r--games/hack/hack.shknam.c2
-rw-r--r--games/hack/hack.topl.c2
5 files changed, 15 insertions, 8 deletions
diff --git a/games/hack/hack.main.c b/games/hack/hack.main.c
index cdec0b2557e..2a663a58cfd 100644
--- a/games/hack/hack.main.c
+++ b/games/hack/hack.main.c
@@ -83,7 +83,7 @@ char *argv[];
/*
* Who am i? Algorithm: 1. Use name as specified in HACKOPTIONS
- * 2. Use $USER or $LOGNAME (if 1. fails)
+ * 2. Use $LOGNAME or $USER (if 1. fails)
* 3. Use getlogin() (if 2. fails)
* The resulting name is overridden by command line options.
* If everything fails, or if the resulting name is some generic
@@ -95,12 +95,14 @@ char *argv[];
{ register char *s;
initoptions();
- if(!*plname && (s = getenv("USER")))
- (void) strncpy(plname, s, sizeof(plname)-1);
if(!*plname && (s = getenv("LOGNAME")))
(void) strncpy(plname, s, sizeof(plname)-1);
+ if(!*plname && (s = getenv("USER")))
+ (void) strncpy(plname, s, sizeof(plname)-1);
if(!*plname && (s = getlogin()))
(void) strncpy(plname, s, sizeof(plname)-1);
+ if(*plname)
+ plname[sizeof(plname)-1] = '\0';
}
/*
@@ -162,12 +164,14 @@ char *argv[];
break;
#endif
case 'u':
- if(argv[0][2])
+ if(argv[0][2]) {
(void) strncpy(plname, argv[0]+2, sizeof(plname)-1);
- else if(argc > 1) {
+ plname[sizeof(plname)-1] = '\0';
+ } else if(argc > 1) {
argc--;
argv++;
(void) strncpy(plname, argv[0], sizeof(plname)-1);
+ plname[sizeof(plname)-1] = '\0';
} else
printf("Player name expected after -u\n");
break;
@@ -175,6 +179,7 @@ char *argv[];
/* allow -T for Tourist, etc. */
(void) strncpy(pl_character, argv[0]+1,
sizeof(pl_character)-1);
+ plname[sizeof(pl_character)-1] = '\0';
/* printf("Unknown option: %s\n", *argv); */
}
diff --git a/games/hack/hack.options.c b/games/hack/hack.options.c
index 078ec7f0de9..361b94230ec 100644
--- a/games/hack/hack.options.c
+++ b/games/hack/hack.options.c
@@ -109,6 +109,7 @@ boolean from_env;
op = index(opts,':');
if(!op) goto bad;
(void) strncpy(plname, op+1, sizeof(plname)-1);
+ plname[sizeof(plname)-1] = '\0';
return;
}
diff --git a/games/hack/hack.shk.c b/games/hack/hack.shk.c
index 6e216b7adca..a3adc7b8358 100644
--- a/games/hack/hack.shk.c
+++ b/games/hack/hack.shk.c
@@ -203,7 +203,8 @@ register roomno = inroom(u.ux,u.uy);
/* He seems to be new here */
ESHK(shopkeeper)->visitct = 0;
ESHK(shopkeeper)->following = 0;
- (void) strncpy(ESHK(shopkeeper)->customer,plname,PL_NSIZ);
+ (void) strncpy(ESHK(shopkeeper)->customer,plname,PL_NSIZ-1);
+ ESHK(shopkeeper)->customer[PL_NSIZ-1] = '\0';
NOTANGRY(shopkeeper) = 1;
}
if(!ESHK(shopkeeper)->following) {
diff --git a/games/hack/hack.shknam.c b/games/hack/hack.shknam.c
index 152dbdb181c..7c045a79d6e 100644
--- a/games/hack/hack.shknam.c
+++ b/games/hack/hack.shknam.c
@@ -140,6 +140,6 @@ register int i;
else (void) strcpy(nampt, "Dirk");
return;
}
- (void) strncpy(nampt, q[i], PL_NSIZ);
+ (void) strncpy(nampt, q[i], PL_NSIZ-1);
nampt[PL_NSIZ-1] = 0;
}
diff --git a/games/hack/hack.topl.c b/games/hack/hack.topl.c
index bd671bc5944..89b8c8937e4 100644
--- a/games/hack/hack.topl.c
+++ b/games/hack/hack.topl.c
@@ -160,7 +160,7 @@ register char *line,*arg1,*arg2,*arg3,*arg4,*arg5,*arg6;
if(!n0) n0 = CO-2;
}
(void) strncpy((tl = eos(toplines)), bp, n0);
- tl[n0] = 0;
+ tl[n0] = '\0';
bp += n0;
/* remove trailing spaces, but leave one */