summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorguenther <guenther@openbsd.org>2015-09-27 05:13:11 +0000
committerguenther <guenther@openbsd.org>2015-09-27 05:13:11 +0000
commit911134d2940395eae97932b9f9c69e48c962c4de (patch)
treeaa0edd5c9e5a2096908820a81a8bf6cdefc85c11
parentDelete obsolete lint comments (diff)
downloadwireguard-openbsd-911134d2940395eae97932b9f9c69e48c962c4de.tar.xz
wireguard-openbsd-911134d2940395eae97932b9f9c69e48c962c4de.zip
Annotate funcs with __attribute__((printf(...))) and clean up the fallout:
* lots of foo(str) --> foo("%s", str) transformations * one totally insane foo(fmt, ap) --> vfoo(fmt, ap) conversion: how did this ever work? * prefer const char[] over char* for static format strings, as it lets gcc check the format and eliminates an unnecessary pointer ok beck@
-rw-r--r--games/hack/hack.apply.c4
-rw-r--r--games/hack/hack.eat.c4
-rw-r--r--games/hack/hack.h12
-rw-r--r--games/hack/hack.invent.c6
-rw-r--r--games/hack/hack.lev.c4
-rw-r--r--games/hack/hack.main.c8
-rw-r--r--games/hack/hack.options.c4
-rw-r--r--games/hack/hack.pager.c6
-rw-r--r--games/hack/hack.potion.c4
-rw-r--r--games/hack/hack.pri.c5
-rw-r--r--games/hack/hack.rip.c8
-rw-r--r--games/hack/hack.rumors.c4
-rw-r--r--games/hack/hack.timeout.c4
-rw-r--r--games/hack/hack.topl.c18
-rw-r--r--games/hack/hack.tty.c6
15 files changed, 52 insertions, 45 deletions
diff --git a/games/hack/hack.apply.c b/games/hack/hack.apply.c
index ff03e258ccc..508cbb1ec4d 100644
--- a/games/hack/hack.apply.c
+++ b/games/hack/hack.apply.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: hack.apply.c,v 1.5 2009/10/27 23:59:25 deraadt Exp $ */
+/* $OpenBSD: hack.apply.c,v 1.6 2015/09/27 05:13:11 guenther Exp $ */
/*
* Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
@@ -374,7 +374,7 @@ dig()
digtxt = "Now what exactly was it that you were digging in?";
mnewsym(dpx, dpy);
prl(dpx, dpy);
- pline(digtxt); /* after mnewsym & prl */
+ pline("%s", digtxt); /* after mnewsym & prl */
return(0);
} else {
if(IS_WALL(levl[dpx][dpy].typ)) {
diff --git a/games/hack/hack.eat.c b/games/hack/hack.eat.c
index b39628b23a3..527d8056f2b 100644
--- a/games/hack/hack.eat.c
+++ b/games/hack/hack.eat.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: hack.eat.c,v 1.8 2009/10/27 23:59:25 deraadt Exp $ */
+/* $OpenBSD: hack.eat.c,v 1.9 2015/09/27 05:13:11 guenther Exp $ */
/*
* Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
@@ -134,7 +134,7 @@ opentin()
useup(tin.tin);
r = rn2(2*TTSZ);
if(r < TTSZ){
- pline(tintxts[r].txt);
+ pline("%s", tintxts[r].txt);
lesshungry(tintxts[r].nut);
if(r == 1) /* SALMON */ {
Glib = rnd(15);
diff --git a/games/hack/hack.h b/games/hack/hack.h
index 9c326e61921..22e1f7c61fd 100644
--- a/games/hack/hack.h
+++ b/games/hack/hack.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: hack.h,v 1.10 2014/03/11 08:05:15 guenther Exp $*/
+/* $OpenBSD: hack.h,v 1.11 2015/09/27 05:13:11 guenther Exp $*/
/* $NetBSD: hack.h,v 1.3 1995/03/23 08:30:21 cgd Exp $*/
/*
@@ -65,6 +65,7 @@
#include "config.h"
#include <string.h>
#include <fcntl.h>
+#include <stdarg.h>
#define Null(type) ((struct type *) 0)
@@ -403,7 +404,7 @@ void mklev(void);
/* hack.main.c */
void glo(int);
void askname(void);
-void impossible(char *, ...);
+void impossible(const char *, ...) __attribute__((__format__ (printf, 1, 2)));
/* ... stuff: fix in files; printf-like ones have spec _attrib or
* something */
void stop_occupation(void);
@@ -519,7 +520,7 @@ int dodip(void);
/* hack.pri.c */
void swallowed(void);
-void panic(char *, ...);
+void panic(const char *, ...) __attribute__((__format__ (printf, 1, 2)));
void atl(int, int, int);
void on_scr(int, int);
void tmp_at(schar, schar);
@@ -631,7 +632,8 @@ void addtopl(char *);
void more(void);
void cmore(char *);
void clrlin(void);
-void pline(char *, ...);
+void pline(const char *, ...) __attribute__((__format__ (printf, 1, 2)));
+void vpline(const char *, va_list) __attribute__((__format__ (printf, 1, 0)));
void putsym(char);
void putstr(char *);
@@ -658,7 +660,7 @@ void drown(void);
void gettty(void);
void settty(char *);
void setftty(void);
-void error(char *, ...);
+void error(const char *, ...) __attribute__((__format__ (printf, 1, 2)));
void getlin(char *);
void getret(void);
void cgetret(char *);
diff --git a/games/hack/hack.invent.c b/games/hack/hack.invent.c
index 43befd4e0a8..f5b355049ab 100644
--- a/games/hack/hack.invent.c
+++ b/games/hack/hack.invent.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: hack.invent.c,v 1.10 2014/03/11 08:05:15 guenther Exp $ */
+/* $OpenBSD: hack.invent.c,v 1.11 2015/09/27 05:13:11 guenther Exp $ */
/*
* Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
@@ -607,7 +607,7 @@ askchain(struct obj *objchn, char *olets, int allflag, int (*fn)(struct obj *),
if(olets && *olets && !strchr(olets, otmp->olet)) continue;
if(ckfn && !(*ckfn)(otmp)) continue;
if(!allflag) {
- pline(xprname(otmp, ilet));
+ pline("%s", xprname(otmp, ilet));
addtopl(" [nyaq]? ");
sym = readchar();
}
@@ -649,7 +649,7 @@ obj_to_let(struct obj *obj)
void
prinv(struct obj *obj)
{
- pline(xprname(obj, obj_to_let(obj)));
+ pline("%s", xprname(obj, obj_to_let(obj)));
}
static char *
diff --git a/games/hack/hack.lev.c b/games/hack/hack.lev.c
index 6b7c59abd00..170f9b2df2f 100644
--- a/games/hack/hack.lev.c
+++ b/games/hack/hack.lev.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: hack.lev.c,v 1.8 2014/03/11 08:05:15 guenther Exp $ */
+/* $OpenBSD: hack.lev.c,v 1.9 2015/09/27 05:13:11 guenther Exp $ */
/*
* Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
@@ -132,7 +132,7 @@ void
bwrite(int fd, const void *loc, ssize_t num)
{
if(write(fd, loc, num) != num)
- panic("cannot write %u bytes to file #%d", num, fd);
+ panic("cannot write %zd bytes to file #%d", num, fd);
}
void
diff --git a/games/hack/hack.main.c b/games/hack/hack.main.c
index 045d4e9cc61..a70659981a2 100644
--- a/games/hack/hack.main.c
+++ b/games/hack/hack.main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: hack.main.c,v 1.16 2014/12/08 21:56:27 deraadt Exp $ */
+/* $OpenBSD: hack.main.c,v 1.17 2015/09/27 05:13:11 guenther Exp $ */
/*
* Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
@@ -403,7 +403,7 @@ not_recovered:
}
if(multi < 0) {
if(!++multi){
- pline(nomovemsg ? nomovemsg :
+ pline("%s", nomovemsg ? nomovemsg :
"You can move again.");
nomovemsg = 0;
if(afternmv) (*afternmv)();
@@ -500,12 +500,12 @@ askname()
}
void
-impossible(char *s, ...)
+impossible(const char *s, ...)
{
va_list ap;
va_start(ap, s);
- pline(s, ap);
+ vpline(s, ap);
va_end(ap);
pline("Program in disorder - perhaps you'd better Quit.");
}
diff --git a/games/hack/hack.options.c b/games/hack/hack.options.c
index efae51c793c..18e96cb6a00 100644
--- a/games/hack/hack.options.c
+++ b/games/hack/hack.options.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: hack.options.c,v 1.9 2009/10/27 23:59:25 deraadt Exp $ */
+/* $OpenBSD: hack.options.c,v 1.10 2015/09/27 05:13:11 guenther Exp $ */
/*
* Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
@@ -261,7 +261,7 @@ doset()
char *eop = eos(buf);
if(*--eop == ',') *eop = 0;
}
- pline(buf);
+ pline("%s", buf);
} else
parseoptions(buf, FALSE);
diff --git a/games/hack/hack.pager.c b/games/hack/hack.pager.c
index 0646c55aeb2..61d382c92ab 100644
--- a/games/hack/hack.pager.c
+++ b/games/hack/hack.pager.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: hack.pager.c,v 1.20 2014/03/11 08:05:15 guenther Exp $ */
+/* $OpenBSD: hack.pager.c,v 1.21 2015/09/27 05:13:11 guenther Exp $ */
/*
* Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
@@ -107,7 +107,7 @@ dowhatis()
(void) strncpy(buf+1, " ", 7);
len = strlen(buf);
}
- pline(buf);
+ pline("%s", buf);
if (buf[len - 1] == ';') {
pline("More info? ");
if (readchar() == 'y') {
@@ -294,7 +294,7 @@ cornline(int mode, char *text)
/* --- now we really do it --- */
if(mode == 2 && linect == 1) /* topline only */
- pline(texthead->line_text);
+ pline("%s", texthead->line_text);
else
if(mode == 2) {
int curline, lth;
diff --git a/games/hack/hack.potion.c b/games/hack/hack.potion.c
index b23962f2c40..8238c02a1c3 100644
--- a/games/hack/hack.potion.c
+++ b/games/hack/hack.potion.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: hack.potion.c,v 1.5 2009/10/27 23:59:25 deraadt Exp $ */
+/* $OpenBSD: hack.potion.c,v 1.6 2015/09/27 05:13:11 guenther Exp $ */
/*
* Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
@@ -273,7 +273,7 @@ strange_feeling(struct obj *obj, char *txt)
if(flags.beginner)
pline("You have a strange feeling for a moment, then it passes.");
else
- pline(txt);
+ pline("%s", txt);
if(!objects[obj->otyp].oc_name_known && !objects[obj->otyp].oc_uname)
docall(obj);
useup(obj);
diff --git a/games/hack/hack.pri.c b/games/hack/hack.pri.c
index b915e65317a..7bb633c0ca2 100644
--- a/games/hack/hack.pri.c
+++ b/games/hack/hack.pri.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: hack.pri.c,v 1.11 2014/03/11 07:41:10 guenther Exp $ */
+/* $OpenBSD: hack.pri.c,v 1.12 2015/09/27 05:13:11 guenther Exp $ */
/*
* Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
@@ -96,11 +96,10 @@ swallowed()
}
-/*VARARGS1*/
boolean panicking;
void
-panic(char *str, ...)
+panic(const char *str, ...)
{
va_list ap;
diff --git a/games/hack/hack.rip.c b/games/hack/hack.rip.c
index c1db2a0a644..454b70ddfc8 100644
--- a/games/hack/hack.rip.c
+++ b/games/hack/hack.rip.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: hack.rip.c,v 1.7 2009/10/27 23:59:25 deraadt Exp $ */
+/* $OpenBSD: hack.rip.c,v 1.8 2015/09/27 05:13:11 guenther Exp $ */
/*
* Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
@@ -66,7 +66,7 @@
extern char plname[];
-static char *riptop= "\
+static const char riptop[] = "\
----------\n\
/ \\\n\
/ REST \\\n\
@@ -74,9 +74,9 @@ static char *riptop= "\
/ PEACE \\\n\
/ \\";
-static char *ripmid = " | %*s%*s |\n";
+static const char ripmid[] = " | %*s%*s |\n";
-static char *ripbot = "\
+static const char ripbot[] = "\
*| * * * | *\n\
_________)/\\\\_//(\\/(/\\)/\\//\\/|_)_______";
diff --git a/games/hack/hack.rumors.c b/games/hack/hack.rumors.c
index 446b9a76310..c73e6f9897e 100644
--- a/games/hack/hack.rumors.c
+++ b/games/hack/hack.rumors.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: hack.rumors.c,v 1.7 2009/10/27 23:59:25 deraadt Exp $ */
+/* $OpenBSD: hack.rumors.c,v 1.8 2015/09/27 05:13:11 guenther Exp $ */
/*
* Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
@@ -105,7 +105,7 @@ outline(FILE *rumf)
if(!fgets(line, sizeof(line), rumf)) return;
line[strcspn(line, "\n")] = '\0';
pline("This cookie has a scrap of paper inside! It reads: ");
- pline(line);
+ pline("%s", line);
}
void
diff --git a/games/hack/hack.timeout.c b/games/hack/hack.timeout.c
index 481a360442a..e456c999ad3 100644
--- a/games/hack/hack.timeout.c
+++ b/games/hack/hack.timeout.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: hack.timeout.c,v 1.5 2009/10/27 23:59:25 deraadt Exp $ */
+/* $OpenBSD: hack.timeout.c,v 1.6 2015/09/27 05:13:11 guenther Exp $ */
/*
* Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
@@ -120,7 +120,7 @@ stoned_dialogue()
long i = (Stoned & TIMEOUT);
if(i > 0 && i <= SIZE(stoned_texts))
- pline(stoned_texts[SIZE(stoned_texts) - i]);
+ pline("%s", stoned_texts[SIZE(stoned_texts) - i]);
if(i == 5)
Fast = 0;
if(i == 3)
diff --git a/games/hack/hack.topl.c b/games/hack/hack.topl.c
index 481475ed3b2..541ed1680ad 100644
--- a/games/hack/hack.topl.c
+++ b/games/hack/hack.topl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: hack.topl.c,v 1.10 2014/03/11 08:05:15 guenther Exp $ */
+/* $OpenBSD: hack.topl.c,v 1.11 2015/09/27 05:13:11 guenther Exp $ */
/*
* Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
@@ -196,19 +196,25 @@ clrlin()
flags.toplin = 0;
}
-/*VARARGS1*/
void
-pline(char *line, ...)
+pline(const char *line, ...)
+{
+ va_list ap;
+
+ va_start(ap, line);
+ vpline(line, ap);
+ va_end(ap);
+}
+
+void
+vpline(const char *line, va_list ap)
{
char pbuf[BUFSZ];
char *bp = pbuf, *tl;
int n,n0;
- va_list ap;
if(!line || !*line) return;
- va_start(ap, line);
(void) vsnprintf(pbuf, sizeof pbuf, line, ap);
- va_end(ap);
if(flags.toplin == 1 && !strcmp(pbuf, toplines)) return;
nscr(); /* %% */
diff --git a/games/hack/hack.tty.c b/games/hack/hack.tty.c
index a4386b048f2..5b3644624f6 100644
--- a/games/hack/hack.tty.c
+++ b/games/hack/hack.tty.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: hack.tty.c,v 1.12 2015/01/15 17:13:37 deraadt Exp $ */
+/* $OpenBSD: hack.tty.c,v 1.13 2015/09/27 05:13:11 guenther Exp $ */
/*-
* Copyright (c) 1988, 1993
@@ -178,12 +178,12 @@ setftty()
/* fatal error */
void
-error(char *s, ...)
+error(const char *s, ...)
{
va_list ap;
if(settty_needed)
- settty((char *) 0);
+ settty(NULL);
va_start(ap, s);
vprintf(s, ap);
va_end(ap);