Tue May 26 00:00:56 2009 UTC ()
sprintf -> snprintf


(dholland)
diff -r1.22 -r1.23 src/games/atc/input.c
diff -r1.19 -r1.20 src/games/atc/log.c
diff -r1.19 -r1.20 src/games/atc/update.c

cvs diff -r1.22 -r1.23 src/games/atc/input.c (expand / switch to unified diff)

--- src/games/atc/input.c 2007/12/15 19:44:38 1.22
+++ src/games/atc/input.c 2009/05/26 00:00:56 1.23
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: input.c,v 1.22 2007/12/15 19:44:38 perry Exp $ */ 1/* $NetBSD: input.c,v 1.23 2009/05/26 00:00:56 dholland Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1990, 1993 4 * Copyright (c) 1990, 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 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Ed James. 8 * Ed James.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -36,27 +36,27 @@ @@ -36,27 +36,27 @@
36 * Copyright (c) 1987 by Ed James, UC Berkeley. All rights reserved. 36 * Copyright (c) 1987 by Ed James, UC Berkeley. All rights reserved.
37 * 37 *
38 * Copy permission is hereby granted provided that this notice is 38 * Copy permission is hereby granted provided that this notice is
39 * retained on all partial or complete copies. 39 * retained on all partial or complete copies.
40 * 40 *
41 * For more info on this and all of my stuff, mail edjames@berkeley.edu. 41 * For more info on this and all of my stuff, mail edjames@berkeley.edu.
42 */ 42 */
43 43
44#include <sys/cdefs.h> 44#include <sys/cdefs.h>
45#ifndef lint 45#ifndef lint
46#if 0 46#if 0
47static char sccsid[] = "@(#)input.c 8.1 (Berkeley) 5/31/93"; 47static char sccsid[] = "@(#)input.c 8.1 (Berkeley) 5/31/93";
48#else 48#else
49__RCSID("$NetBSD: input.c,v 1.22 2007/12/15 19:44:38 perry Exp $"); 49__RCSID("$NetBSD: input.c,v 1.23 2009/05/26 00:00:56 dholland Exp $");
50#endif 50#endif
51#endif /* not lint */ 51#endif /* not lint */
52 52
53#include "include.h" 53#include "include.h"
54#include "pathnames.h" 54#include "pathnames.h"
55 55
56#define MAXRULES 6 56#define MAXRULES 6
57#define MAXDEPTH 15 57#define MAXDEPTH 15
58 58
59#define RETTOKEN '\n' 59#define RETTOKEN '\n'
60#define REDRAWTOKEN '\014' /* CTRL(L) */ 60#define REDRAWTOKEN '\014' /* CTRL(L) */
61#define SHELLTOKEN '!' 61#define SHELLTOKEN '!'
62#define HELPTOKEN '?' 62#define HELPTOKEN '?'
@@ -198,27 +198,28 @@ rezero(void) @@ -198,27 +198,28 @@ rezero(void)
198 T_STATE = 0; 198 T_STATE = 0;
199 T_RULE = -1; 199 T_RULE = -1;
200 T_CH = -1; 200 T_CH = -1;
201 T_POS = 0; 201 T_POS = 0;
202 (void)strcpy(T_STR, ""); 202 (void)strcpy(T_STR, "");
203} 203}
204 204
205void 205void
206push(int ruleno, int ch) 206push(int ruleno, int ch)
207{ 207{
208 int newstate, newpos; 208 int newstate, newpos;
209 209
210 assert(level < (MAXDEPTH - 1)); 210 assert(level < (MAXDEPTH - 1));
211 (void)sprintf(T_STR, st[T_STATE].rule[ruleno].str, tval); 211 (void)snprintf(T_STR, sizeof(T_STR),
 212 st[T_STATE].rule[ruleno].str, tval);
212 T_RULE = ruleno; 213 T_RULE = ruleno;
213 T_CH = ch; 214 T_CH = ch;
214 newstate = st[T_STATE].rule[ruleno].to_state; 215 newstate = st[T_STATE].rule[ruleno].to_state;
215 newpos = T_POS + strlen(T_STR); 216 newpos = T_POS + strlen(T_STR);
216 217
217 ioaddstr(T_POS, T_STR); 218 ioaddstr(T_POS, T_STR);
218 219
219 if (level == 0) 220 if (level == 0)
220 ioclrtobot(); 221 ioclrtobot();
221 level++; 222 level++;
222 T_STATE = newstate; 223 T_STATE = newstate;
223 T_POS = newpos; 224 T_POS = newpos;
224 T_RULE = -1; 225 T_RULE = -1;

cvs diff -r1.19 -r1.20 src/games/atc/log.c (expand / switch to unified diff)

--- src/games/atc/log.c 2007/12/15 19:44:38 1.19
+++ src/games/atc/log.c 2009/05/26 00:00:56 1.20
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: log.c,v 1.19 2007/12/15 19:44:38 perry Exp $ */ 1/* $NetBSD: log.c,v 1.20 2009/05/26 00:00:56 dholland Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1990, 1993 4 * Copyright (c) 1990, 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 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Ed James. 8 * Ed James.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -36,27 +36,27 @@ @@ -36,27 +36,27 @@
36 * Copyright (c) 1987 by Ed James, UC Berkeley. All rights reserved. 36 * Copyright (c) 1987 by Ed James, UC Berkeley. All rights reserved.
37 * 37 *
38 * Copy permission is hereby granted provided that this notice is 38 * Copy permission is hereby granted provided that this notice is
39 * retained on all partial or complete copies. 39 * retained on all partial or complete copies.
40 * 40 *
41 * For more info on this and all of my stuff, mail edjames@berkeley.edu. 41 * For more info on this and all of my stuff, mail edjames@berkeley.edu.
42 */ 42 */
43 43
44#include <sys/cdefs.h> 44#include <sys/cdefs.h>
45#ifndef lint 45#ifndef lint
46#if 0 46#if 0
47static char sccsid[] = "@(#)log.c 8.1 (Berkeley) 5/31/93"; 47static char sccsid[] = "@(#)log.c 8.1 (Berkeley) 5/31/93";
48#else 48#else
49__RCSID("$NetBSD: log.c,v 1.19 2007/12/15 19:44:38 perry Exp $"); 49__RCSID("$NetBSD: log.c,v 1.20 2009/05/26 00:00:56 dholland Exp $");
50#endif 50#endif
51#endif /* not lint */ 51#endif /* not lint */
52 52
53#include "include.h" 53#include "include.h"
54#include "pathnames.h" 54#include "pathnames.h"
55 55
56static FILE *score_fp; 56static FILE *score_fp;
57 57
58int 58int
59compar(const void *va, const void *vb) 59compar(const void *va, const void *vb)
60{ 60{
61 const SCORE *a, *b; 61 const SCORE *a, *b;
62 62
@@ -74,33 +74,34 @@ compar(const void *va, const void *vb) @@ -74,33 +74,34 @@ compar(const void *va, const void *vb)
74#define SECAHOUR (SECAMIN * MINAHOUR) 74#define SECAHOUR (SECAMIN * MINAHOUR)
75#define SECADAY (SECAHOUR * HOURADAY) 75#define SECADAY (SECAHOUR * HOURADAY)
76#define DAY(t) ((t) / SECADAY) 76#define DAY(t) ((t) / SECADAY)
77#define HOUR(t) (((t) % SECADAY) / SECAHOUR) 77#define HOUR(t) (((t) % SECADAY) / SECAHOUR)
78#define MIN(t) (((t) % SECAHOUR) / SECAMIN) 78#define MIN(t) (((t) % SECAHOUR) / SECAMIN)
79#define SEC(t) ((t) % SECAMIN) 79#define SEC(t) ((t) % SECAMIN)
80 80
81const char * 81const char *
82timestr(int t) 82timestr(int t)
83{ 83{
84 static char s[80]; 84 static char s[80];
85 85
86 if (DAY(t) > 0) 86 if (DAY(t) > 0)
87 (void)sprintf(s, "%dd+%02dhrs", DAY(t), HOUR(t)); 87 (void)snprintf(s, sizeof(s), "%dd+%02dhrs", DAY(t), HOUR(t));
88 else if (HOUR(t) > 0) 88 else if (HOUR(t) > 0)
89 (void)sprintf(s, "%d:%02d:%02d", HOUR(t), MIN(t), SEC(t)); 89 (void)snprintf(s, sizeof(s), "%d:%02d:%02d", HOUR(t), MIN(t),
 90 SEC(t));
90 else if (MIN(t) > 0) 91 else if (MIN(t) > 0)
91 (void)sprintf(s, "%d:%02d", MIN(t), SEC(t)); 92 (void)snprintf(s, sizeof(s), "%d:%02d", MIN(t), SEC(t));
92 else if (SEC(t) > 0) 93 else if (SEC(t) > 0)
93 (void)sprintf(s, ":%02d", SEC(t)); 94 (void)snprintf(s, sizeof(s), ":%02d", SEC(t));
94 else 95 else
95 *s = '\0'; 96 *s = '\0';
96 97
97 return (s); 98 return (s);
98} 99}
99 100
100void 101void
101open_score_file(void) 102open_score_file(void)
102{ 103{
103 mode_t old_mask; 104 mode_t old_mask;
104 int score_fd; 105 int score_fd;
105 int flags; 106 int flags;
106 107

cvs diff -r1.19 -r1.20 src/games/atc/update.c (expand / switch to unified diff)

--- src/games/atc/update.c 2007/12/15 19:44:38 1.19
+++ src/games/atc/update.c 2009/05/26 00:00:56 1.20
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: update.c,v 1.19 2007/12/15 19:44:38 perry Exp $ */ 1/* $NetBSD: update.c,v 1.20 2009/05/26 00:00:56 dholland Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1990, 1993 4 * Copyright (c) 1990, 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 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Ed James. 8 * Ed James.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -36,27 +36,27 @@ @@ -36,27 +36,27 @@
36 * Copyright (c) 1987 by Ed James, UC Berkeley. All rights reserved. 36 * Copyright (c) 1987 by Ed James, UC Berkeley. All rights reserved.
37 * 37 *
38 * Copy permission is hereby granted provided that this notice is 38 * Copy permission is hereby granted provided that this notice is
39 * retained on all partial or complete copies. 39 * retained on all partial or complete copies.
40 * 40 *
41 * For more info on this and all of my stuff, mail edjames@berkeley.edu. 41 * For more info on this and all of my stuff, mail edjames@berkeley.edu.
42 */ 42 */
43 43
44#include <sys/cdefs.h> 44#include <sys/cdefs.h>
45#ifndef lint 45#ifndef lint
46#if 0 46#if 0
47static char sccsid[] = "@(#)update.c 8.1 (Berkeley) 5/31/93"; 47static char sccsid[] = "@(#)update.c 8.1 (Berkeley) 5/31/93";
48#else 48#else
49__RCSID("$NetBSD: update.c,v 1.19 2007/12/15 19:44:38 perry Exp $"); 49__RCSID("$NetBSD: update.c,v 1.20 2009/05/26 00:00:56 dholland Exp $");
50#endif 50#endif
51#endif /* not lint */ 51#endif /* not lint */
52 52
53#include "include.h" 53#include "include.h"
54 54
55/* ARGSUSED */ 55/* ARGSUSED */
56void 56void
57update(int dummy __unused) 57update(int dummy __unused)
58{ 58{
59 int i, dir_diff, unclean; 59 int i, dir_diff, unclean;
60 PLANE *pp, *p1, *p2; 60 PLANE *pp, *p1, *p2;
61 61
62#ifdef SYSV 62#ifdef SYSV
@@ -191,70 +191,76 @@ update(int dummy __unused) @@ -191,70 +191,76 @@ update(int dummy __unused)
191 if (pp->status == S_GONE) { 191 if (pp->status == S_GONE) {
192 safe_planes++; 192 safe_planes++;
193 delete(&air, pp); 193 delete(&air, pp);
194 } 194 }
195 } 195 }
196 196
197 draw_all(); 197 draw_all();
198 198
199 for (p1 = air.head; p1 != NULL; p1 = p1->next) 199 for (p1 = air.head; p1 != NULL; p1 = p1->next)
200 for (p2 = p1->next; p2 != NULL; p2 = p2->next) 200 for (p2 = p1->next; p2 != NULL; p2 = p2->next)
201 if (too_close(p1, p2, 1)) { 201 if (too_close(p1, p2, 1)) {
202 static char buf[80]; 202 static char buf[80];
203 203
204 (void)sprintf(buf, "collided with plane '%c'.", 204 (void)snprintf(buf, sizeof(buf),
 205 "collided with plane '%c'.",
205 name(p2)); 206 name(p2));
206 loser(p1, buf); 207 loser(p1, buf);
207 } 208 }
208 /* 209 /*
209 * Check every other update. Actually, only add on even updates. 210 * Check every other update. Actually, only add on even updates.
210 * Otherwise, prop jobs show up *on* entrance. Remember that 211 * Otherwise, prop jobs show up *on* entrance. Remember that
211 * we don't update props on odd updates. 212 * we don't update props on odd updates.
212 */ 213 */
213 if ((rand() % sp->newplane_time) == 0) 214 if ((rand() % sp->newplane_time) == 0)
214 (void)addplane(); 215 (void)addplane();
215 216
216#ifdef SYSV 217#ifdef SYSV
217 alarm(sp->update_secs); 218 alarm(sp->update_secs);
218#endif 219#endif
219} 220}
220 221
221const char * 222const char *
222command(const PLANE *pp) 223command(const PLANE *pp)
223{ 224{
224 static char buf[50], *bp, *comm_start; 225 static char buf[50], *bp, *comm_start;
 226 size_t bpsize;
225 227
226 buf[0] = '\0'; 228 buf[0] = '\0';
227 bp = buf; 229 bp = buf;
228 (void)sprintf(bp, "%c%d%c%c%d: ", name(pp), pp->altitude,  230 bpsize = sizeof(buf);
 231 (void)snprintf(bp, bpsize, "%c%d%c%c%d: ", name(pp), pp->altitude,
229 (pp->fuel < LOWFUEL) ? '*' : ' ', 232 (pp->fuel < LOWFUEL) ? '*' : ' ',
230 (pp->dest_type == T_AIRPORT) ? 'A' : 'E', pp->dest_no); 233 (pp->dest_type == T_AIRPORT) ? 'A' : 'E', pp->dest_no);
231 234
232 comm_start = bp = strchr(buf, '\0'); 235 comm_start = bp = strchr(buf, '\0');
 236 bpsize = buf + sizeof(buf) - bp;
233 if (pp->altitude == 0) 237 if (pp->altitude == 0)
234 (void)sprintf(bp, "Holding @ A%d", pp->orig_no); 238 (void)snprintf(bp, bpsize, "Holding @ A%d", pp->orig_no);
235 else if (pp->new_dir >= MAXDIR || pp->new_dir < 0) 239 else if (pp->new_dir >= MAXDIR || pp->new_dir < 0)
236 (void)strcpy(bp, "Circle"); 240 (void)snprintf(bp, bpsize, "Circle");
237 else if (pp->new_dir != pp->dir) 241 else if (pp->new_dir != pp->dir)
238 (void)sprintf(bp, "%d", dir_deg(pp->new_dir)); 242 (void)snprintf(bp, bpsize, "%d", dir_deg(pp->new_dir));
239 243
240 bp = strchr(buf, '\0'); 244 bp = strchr(buf, '\0');
 245 bpsize = buf + sizeof(buf) - bp;
241 if (pp->delayd) 246 if (pp->delayd)
242 (void)sprintf(bp, " @ B%d", pp->delayd_no); 247 (void)snprintf(bp, bpsize, " @ B%d", pp->delayd_no);
243 248
244 bp = strchr(buf, '\0'); 249 bp = strchr(buf, '\0');
 250 bpsize = buf + sizeof(buf) - bp;
245 if (*comm_start == '\0' &&  251 if (*comm_start == '\0' &&
246 (pp->status == S_UNMARKED || pp->status == S_IGNORED)) 252 (pp->status == S_UNMARKED || pp->status == S_IGNORED))
247 (void)strcpy(bp, "---------"); 253 (void)snprintf(bp, bpsize, "---------");
248 return (buf); 254 return (buf);
249} 255}
250 256
251char 257char
252name(const PLANE *p) 258name(const PLANE *p)
253{ 259{
254 if (p->plane_type == 0) 260 if (p->plane_type == 0)
255 return ('A' + p->plane_no); 261 return ('A' + p->plane_no);
256 else 262 else
257 return ('a' + p->plane_no); 263 return ('a' + p->plane_no);
258} 264}
259 265
260int 266int