1
0
mirror of https://github.com/openbsd/src.git synced 2025-01-10 06:47:55 -08:00

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@
This commit is contained in:
guenther 2015-09-27 05:13:11 +00:00
parent c651476829
commit 911134d294
15 changed files with 52 additions and 45 deletions

View File

@ -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)) {

View File

@ -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);

View File

@ -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 *);

View File

@ -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 *

View File

@ -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

View File

@ -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.");
}

View File

@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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\
_________)/\\\\_//(\\/(/\\)/\\//\\/|_)_______";

View File

@ -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

View File

@ -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)

View File

@ -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(); /* %% */

View File

@ -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);