Mon May 25 00:43:34 2009 UTC ()
sprintf -> snprintf.


(dholland)
diff -r1.16 -r1.17 src/games/trek/getpar.c
diff -r1.11 -r1.12 src/games/trek/shield.c

cvs diff -r1.16 -r1.17 src/games/trek/getpar.c (expand / switch to unified diff)

--- src/games/trek/getpar.c 2009/05/25 00:39:45 1.16
+++ src/games/trek/getpar.c 2009/05/25 00:43:34 1.17
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: getpar.c,v 1.16 2009/05/25 00:39:45 dholland Exp $ */ 1/* $NetBSD: getpar.c,v 1.17 2009/05/25 00:43:34 dholland Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1980, 1993 4 * Copyright (c) 1980, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -24,27 +24,27 @@ @@ -24,27 +24,27 @@
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE. 29 * SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33#ifndef lint 33#ifndef lint
34#if 0 34#if 0
35static char sccsid[] = "@(#)getpar.c 8.1 (Berkeley) 5/31/93"; 35static char sccsid[] = "@(#)getpar.c 8.1 (Berkeley) 5/31/93";
36#else 36#else
37__RCSID("$NetBSD: getpar.c,v 1.16 2009/05/25 00:39:45 dholland Exp $"); 37__RCSID("$NetBSD: getpar.c,v 1.17 2009/05/25 00:43:34 dholland Exp $");
38#endif 38#endif
39#endif /* not lint */ 39#endif /* not lint */
40 40
41#include <stdio.h> 41#include <stdio.h>
42#include <stdlib.h> 42#include <stdlib.h>
43#include <string.h> 43#include <string.h>
44#include "getpar.h" 44#include "getpar.h"
45#include "trek.h" 45#include "trek.h"
46 46
47static int testterm(void); 47static int testterm(void);
48 48
49/** 49/**
50 ** get integer parameter 50 ** get integer parameter
@@ -187,27 +187,27 @@ getcodpar(const char *s, const struct cv @@ -187,27 +187,27 @@ getcodpar(const char *s, const struct cv
187/** 187/**
188 ** get string parameter 188 ** get string parameter
189 **/ 189 **/
190 190
191void 191void
192getstrpar(const char *s, char *r, int l, const char *t) 192getstrpar(const char *s, char *r, int l, const char *t)
193{ 193{
194 int i; 194 int i;
195 char format[20]; 195 char format[20];
196 int f; 196 int f;
197 197
198 if (t == 0) 198 if (t == 0)
199 t = " \t\n;"; 199 t = " \t\n;";
200 (void)sprintf(format, "%%%d[^%s]", l, t); 200 (void)snprintf(format, sizeof(format), "%%%d[^%s]", l, t);
201 while (1) { 201 while (1) {
202 if ((f = testnl()) && s) 202 if ((f = testnl()) && s)
203 printf("%s: ", s); 203 printf("%s: ", s);
204 if (f) 204 if (f)
205 getchar(); 205 getchar();
206 scanf("%*[\t ;]"); 206 scanf("%*[\t ;]");
207 i = scanf(format, r); 207 i = scanf(format, r);
208 if (i < 0) 208 if (i < 0)
209 exit(1); 209 exit(1);
210 if (i != 0) 210 if (i != 0)
211 return; 211 return;
212 } 212 }
213} 213}

cvs diff -r1.11 -r1.12 src/games/trek/shield.c (expand / switch to unified diff)

--- src/games/trek/shield.c 2009/05/24 22:55:03 1.11
+++ src/games/trek/shield.c 2009/05/25 00:43:34 1.12
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: shield.c,v 1.11 2009/05/24 22:55:03 dholland Exp $ */ 1/* $NetBSD: shield.c,v 1.12 2009/05/25 00:43:34 dholland Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1980, 1993 4 * Copyright (c) 1980, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -24,27 +24,27 @@ @@ -24,27 +24,27 @@
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE. 29 * SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33#ifndef lint 33#ifndef lint
34#if 0 34#if 0
35static char sccsid[] = "@(#)shield.c 8.1 (Berkeley) 5/31/93"; 35static char sccsid[] = "@(#)shield.c 8.1 (Berkeley) 5/31/93";
36#else 36#else
37__RCSID("$NetBSD: shield.c,v 1.11 2009/05/24 22:55:03 dholland Exp $"); 37__RCSID("$NetBSD: shield.c,v 1.12 2009/05/25 00:43:34 dholland Exp $");
38#endif 38#endif
39#endif /* not lint */ 39#endif /* not lint */
40 40
41#include <stdio.h> 41#include <stdio.h>
42#include "trek.h" 42#include "trek.h"
43#include "getpar.h" 43#include "getpar.h"
44 44
45/* 45/*
46** SHIELD AND CLOAKING DEVICE CONTROL 46** SHIELD AND CLOAKING DEVICE CONTROL
47** 47**
48** 'f' is one for auto shield up (in case of Condition RED), 48** 'f' is one for auto shield up (in case of Condition RED),
49** zero for shield control, and negative one for cloaking 49** zero for shield control, and negative one for cloaking
50** device control. 50** device control.
@@ -101,30 +101,32 @@ shield(int f) @@ -101,30 +101,32 @@ shield(int f)
101 if (f <= 0) 101 if (f <= 0)
102 out(ind); 102 out(ind);
103 return; 103 return;
104 } 104 }
105 if (Ship.cond == DOCKED) { 105 if (Ship.cond == DOCKED) {
106 printf("%s %s down while docked\n", device, dev2); 106 printf("%s %s down while docked\n", device, dev2);
107 return; 107 return;
108 } 108 }
109 if (f <= 0 && !testnl()) { 109 if (f <= 0 && !testnl()) {
110 r = getcodpar("Up or down", Udtab); 110 r = getcodpar("Up or down", Udtab);
111 i = (long) r->value; 111 i = (long) r->value;
112 } else { 112 } else {
113 if (*stat) 113 if (*stat)
114 (void)sprintf(s, "%s %s up. Do you want %s down", 114 (void)snprintf(s, sizeof(s),
 115 "%s %s up. Do you want %s down",
115 device, dev2, dev3); 116 device, dev2, dev3);
116 else 117 else
117 (void)sprintf(s, "%s %s down. Do you want %s up", 118 (void)snprintf(s, sizeof(s),
 119 "%s %s down. Do you want %s up",
118 device, dev2, dev3); 120 device, dev2, dev3);
119 if (!getynpar(s)) 121 if (!getynpar(s))
120 return; 122 return;
121 i = !*stat; 123 i = !*stat;
122 } 124 }
123 if (*stat == i) { 125 if (*stat == i) {
124 printf("%s already ", device); 126 printf("%s already ", device);
125 if (i) 127 if (i)
126 printf("up\n"); 128 printf("up\n");
127 else 129 else
128 printf("down\n"); 130 printf("down\n");
129 return; 131 return;
130 } 132 }