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

Split error() into error() and warning() so error() can be marked __dead to

appease gcc.

ok procter@ deraadt@
This commit is contained in:
krw 2017-01-20 10:26:16 +00:00
parent 19b4f733e9
commit 5c4e30b8f3
6 changed files with 29 additions and 22 deletions

View File

@ -1,4 +1,4 @@
/* $OpenBSD: compile.c,v 1.40 2015/10/26 22:24:44 jca Exp $ */ /* $OpenBSD: compile.c,v 1.41 2017/01/20 10:26:16 krw Exp $ */
/*- /*-
* Copyright (c) 1992 Diomidis Spinellis. * Copyright (c) 1992 Diomidis Spinellis.
@ -520,14 +520,12 @@ compile_subst(char *p, struct s_subst *s)
} else if (*p == '\n') { } else if (*p == '\n') {
error(COMPILE, error(COMPILE,
"unescaped newline inside substitute pattern"); "unescaped newline inside substitute pattern");
/* NOTREACHED */
} }
*sp++ = *p; *sp++ = *p;
} }
size += sp - op; size += sp - op;
} while ((p = cu_fgets(&lbuf, &bufsize))); } while ((p = cu_fgets(&lbuf, &bufsize)));
error(COMPILE, "unterminated substitute in regular expression"); error(COMPILE, "unterminated substitute in regular expression");
/* NOTREACHED */
} }
/* /*
@ -578,7 +576,7 @@ compile_flags(char *p, struct s_subst *s)
p++; p++;
#ifdef HISTORIC_PRACTICE #ifdef HISTORIC_PRACTICE
if (*p != ' ') { if (*p != ' ') {
error(WARNING, "space missing before w wfile"); warning("space missing before w wfile");
return (p); return (p);
} }
#endif #endif
@ -750,7 +748,7 @@ duptoeol(char *s, char *ctype, char **semi)
*s = '\0'; *s = '\0';
} }
if (ws) if (ws)
error(WARNING, "whitespace after %s", ctype); warning("whitespace after %s", ctype);
len = s - start + 1; len = s - start + 1;
if (semi) if (semi)
*semi = s; *semi = s;
@ -854,7 +852,7 @@ uselabel(void)
for (lh = labels[i]; lh != NULL; lh = next) { for (lh = labels[i]; lh != NULL; lh = next) {
next = lh->lh_next; next = lh->lh_next;
if (!lh->lh_ref) if (!lh->lh_ref)
error(WARNING, "unused label '%s'", warning("unused label '%s'",
lh->lh_cmd->t); lh->lh_cmd->t);
free(lh); free(lh);
} }

View File

@ -1,4 +1,4 @@
/* $OpenBSD: defs.h,v 1.7 2015/10/26 22:24:44 jca Exp $ */ /* $OpenBSD: defs.h,v 1.8 2017/01/20 10:26:16 krw Exp $ */
/*- /*-
* Copyright (c) 1992 Diomidis Spinellis. * Copyright (c) 1992 Diomidis Spinellis.
* Copyright (c) 1992, 1993 * Copyright (c) 1992, 1993
@ -136,7 +136,6 @@ typedef struct {
/* /*
* Error severity codes: * Error severity codes:
*/ */
#define WARNING 0 /* Just print the warning */
#define FATAL 1 /* Exit immediately with 1 */ #define FATAL 1 /* Exit immediately with 1 */
#define COMPILE 2 /* Print error, count and finish script */ #define COMPILE 2 /* Print error, count and finish script */

View File

@ -1,4 +1,4 @@
/* $OpenBSD: extern.h,v 1.11 2015/10/26 14:08:47 mmcc Exp $ */ /* $OpenBSD: extern.h,v 1.12 2017/01/20 10:26:16 krw Exp $ */
/*- /*-
* Copyright (c) 1992 Diomidis Spinellis. * Copyright (c) 1992 Diomidis Spinellis.
* Copyright (c) 1992, 1993 * Copyright (c) 1992, 1993
@ -48,7 +48,8 @@ void cfclose(struct s_command *, struct s_command *);
void compile(void); void compile(void);
void cspace(SPACE *, const char *, size_t, enum e_spflag); void cspace(SPACE *, const char *, size_t, enum e_spflag);
char *cu_fgets(char **, size_t *); char *cu_fgets(char **, size_t *);
void error(int, const char *, ...); __dead void error(int, const char *, ...);
void warning(const char *, ...);
int mf_fgets(SPACE *, enum e_spflag); int mf_fgets(SPACE *, enum e_spflag);
int lastline(void); int lastline(void);
void process(void); void process(void);

View File

@ -1,4 +1,4 @@
/* $OpenBSD: main.c,v 1.33 2016/07/14 08:31:18 semarie Exp $ */ /* $OpenBSD: main.c,v 1.34 2017/01/20 10:26:16 krw Exp $ */
/*- /*-
* Copyright (c) 1992 Diomidis Spinellis. * Copyright (c) 1992 Diomidis Spinellis.
@ -285,7 +285,8 @@ again:
} }
} }
} }
/* NOTREACHED */
return (NULL);
} }
/* /*
@ -329,7 +330,7 @@ mf_fgets(SPACE *sp, enum e_spflag spflag)
fclose(infile); fclose(infile);
if (*oldfname != '\0') { if (*oldfname != '\0') {
if (rename(fname, oldfname) != 0) { if (rename(fname, oldfname) != 0) {
error(WARNING, "rename()"); warning("rename()");
unlink(tmpfname); unlink(tmpfname);
exit(1); exit(1);
} }
@ -389,7 +390,7 @@ mf_fgets(SPACE *sp, enum e_spflag spflag)
outfname = "stdout"; outfname = "stdout";
} }
if ((infile = fopen(fname, "r")) == NULL) { if ((infile = fopen(fname, "r")) == NULL) {
error(WARNING, "%s", strerror(errno)); warning("%s", strerror(errno));
rval = 1; rval = 1;
continue; continue;
} }

View File

@ -1,4 +1,4 @@
/* $OpenBSD: misc.c,v 1.11 2015/10/26 14:08:47 mmcc Exp $ */ /* $OpenBSD: misc.c,v 1.12 2017/01/20 10:26:16 krw Exp $ */
/*- /*-
* Copyright (c) 1992 Diomidis Spinellis. * Copyright (c) 1992 Diomidis Spinellis.
@ -101,7 +101,7 @@ strregerror(int errcode, regex_t *preg)
/* /*
* Error reporting function * Error reporting function
*/ */
void __dead void
error(int severity, const char *fmt, ...) error(int severity, const char *fmt, ...)
{ {
va_list ap; va_list ap;
@ -109,15 +109,24 @@ error(int severity, const char *fmt, ...)
va_start(ap, fmt); va_start(ap, fmt);
(void)fprintf(stderr, "sed: "); (void)fprintf(stderr, "sed: ");
switch (severity) { switch (severity) {
case WARNING:
case COMPILE: case COMPILE:
(void)fprintf(stderr, "%lu: %s: ", linenum, fname); (void)fprintf(stderr, "%lu: %s: ", linenum, fname);
} }
(void)vfprintf(stderr, fmt, ap); (void)vfprintf(stderr, fmt, ap);
va_end(ap); va_end(ap);
(void)fprintf(stderr, "\n"); (void)fprintf(stderr, "\n");
if (severity == WARNING)
return;
exit(1); exit(1);
/* NOTREACHED */ }
void
warning(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
(void)fprintf(stderr, "sed: ");
(void)fprintf(stderr, "%lu: %s: ", linenum, fname);
(void)vfprintf(stderr, fmt, ap);
va_end(ap);
(void)fprintf(stderr, "\n");
} }

View File

@ -1,4 +1,4 @@
/* $OpenBSD: process.c,v 1.29 2016/10/11 19:27:39 martijn Exp $ */ /* $OpenBSD: process.c,v 1.30 2017/01/20 10:26:16 krw Exp $ */
/*- /*-
* Copyright (c) 1992 Diomidis Spinellis. * Copyright (c) 1992 Diomidis Spinellis.
@ -539,7 +539,6 @@ regexec_e(regex_t *preg, const char *string, int eflags,
return (0); return (0);
} }
error(FATAL, "RE error: %s", strregerror(eval, defpreg)); error(FATAL, "RE error: %s", strregerror(eval, defpreg));
/* NOTREACHED */
} }
/* /*