Crank WARNS.
Cast sizeof() to (int), as it's being compared against an int, not a size_t. If i is changed to a size_t, it means the logic must be slightly changed later in the flow, where --i is checked to be >= 0. I am not sure I want to make a logic change to account for clearing up a warning, when an aesthetic one will keep from modifying the logic. Other harmless casts, that I think I've made in the right directions. Make gpbc() an inline function, rather than an obfuscated macro, make its scratch space local, rather than global. The previous macro used a dirty hack (logical AND in place of a conditional) which would lead GCC to throw a fit (rightly so) as the logical check, as well as the incrementation of a variable, were not used for anything. const'ify a few places where gcc3 yells. xstrdup() some global consts in places where we xstrdup() when not using consts, but tried to assign them to non-consts before. Don't use execv(2) if we don't have the kind of arguments it wants. Reviewed by: asmodai obrien tjr Submitted by: tjr (a gcc3 build log)
This commit is contained in:
parent
2e75617aaf
commit
ecccdb8703
@ -8,6 +8,7 @@ PROG= m4
|
||||
CFLAGS+=-DEXTENDED
|
||||
|
||||
SRCS= eval.c expr.c look.c main.c misc.c gnum4.c trace.c
|
||||
WARNS?= 2
|
||||
MAN= m4.1
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
@ -593,12 +593,12 @@ dodefine(name, defn)
|
||||
p->type = n & TYPEMASK;
|
||||
if ((n & NOARGS) == 0)
|
||||
p->type |= NEEDARGS;
|
||||
p->defn = null;
|
||||
p->defn = xstrdup(null);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!*defn)
|
||||
p->defn = null;
|
||||
p->defn = xstrdup(null);
|
||||
else
|
||||
p->defn = xstrdup(defn);
|
||||
p->type = MACRTYPE;
|
||||
@ -615,7 +615,7 @@ dodefn(name)
|
||||
const char *name;
|
||||
{
|
||||
ndptr p;
|
||||
char *real;
|
||||
const char *real;
|
||||
|
||||
if ((p = lookup(name)) != nil) {
|
||||
if (p->defn != null) {
|
||||
@ -648,7 +648,7 @@ dopushdef(name, defn)
|
||||
CURRENT_LINE);
|
||||
p = addent(name);
|
||||
if (!*defn)
|
||||
p->defn = null;
|
||||
p->defn = xstrdup(null);
|
||||
else
|
||||
p->defn = xstrdup(defn);
|
||||
p->type = MACRTYPE;
|
||||
@ -663,7 +663,7 @@ static void
|
||||
dump_one_def(p)
|
||||
ndptr p;
|
||||
{
|
||||
char *real;
|
||||
const char *real;
|
||||
|
||||
if (mimic_gnu) {
|
||||
if ((p->type & TYPEMASK) == MACRTYPE)
|
||||
|
@ -245,21 +245,19 @@ not()
|
||||
static int
|
||||
eqrel()
|
||||
{
|
||||
int vl, vr, eqrel;
|
||||
int vl, vr, eqrelval;
|
||||
|
||||
vl = shift();
|
||||
while ((eqrel = geteqrel()) != -1) {
|
||||
while ((eqrelval = geteqrel()) != -1) {
|
||||
vr = shift();
|
||||
|
||||
switch (eqrel) {
|
||||
|
||||
switch (eqrelval) {
|
||||
case EQL:
|
||||
vl = (vl == vr);
|
||||
break;
|
||||
case NEQ:
|
||||
vl = (vl != vr);
|
||||
break;
|
||||
|
||||
case LEQ:
|
||||
vl = (vl <= vr);
|
||||
break;
|
||||
@ -446,7 +444,7 @@ constant()
|
||||
ungetch();
|
||||
return num();
|
||||
}
|
||||
for (i = 0; i < sizeof(int); i++) {
|
||||
for (i = 0; i < (int)sizeof(int); i++) {
|
||||
if ((c = getch()) == '\'') {
|
||||
ungetch();
|
||||
break;
|
||||
|
@ -71,7 +71,7 @@ extern void remhash(const char *, int);
|
||||
/* main.c */
|
||||
extern void outputstr(const char *);
|
||||
extern int builtin_type(const char *);
|
||||
extern char *builtin_realname(int);
|
||||
extern const char *builtin_realname(int);
|
||||
extern void emitline(void);
|
||||
|
||||
/* misc.c */
|
||||
@ -148,11 +148,27 @@ extern char *bbase[]; /* buffer base per ilevel */
|
||||
extern char ecommt[MAXCCHARS+1];/* end character for comment */
|
||||
extern char *ep; /* first free char in strspace */
|
||||
extern char lquote[MAXCCHARS+1];/* left quote character (`) */
|
||||
extern char *m4wraps; /* m4wrap string default. */
|
||||
extern char *null; /* as it says.. just a null. */
|
||||
extern const char *m4wraps; /* m4wrap string default. */
|
||||
extern const char *null; /* as it says.. just a null. */
|
||||
extern char rquote[MAXCCHARS+1];/* right quote character (') */
|
||||
extern char scommt[MAXCCHARS+1];/* start character for comment */
|
||||
extern int synccpp; /* Line synchronisation for C preprocessor */
|
||||
extern int chscratch; /* Scratch space for gpbc() macro */
|
||||
|
||||
extern int mimic_gnu; /* behaves like gnu-m4 */
|
||||
|
||||
/* get a possibly pushed-back-character, increment lineno if need be */
|
||||
static __inline int gpbc(void)
|
||||
{
|
||||
int chscratch; /* Scratch space. */
|
||||
|
||||
if (bp > bufbase) {
|
||||
if (*--bp)
|
||||
return (*bp);
|
||||
else
|
||||
return (EOF);
|
||||
}
|
||||
chscratch = obtain_char(infile+ilevel);
|
||||
if (chscratch == '\n')
|
||||
++inlineno[ilevel];
|
||||
return (chscratch);
|
||||
}
|
||||
|
@ -208,7 +208,7 @@ static void exit_regerror(int, regex_t *);
|
||||
static void do_subst(const char *, regex_t *, const char *, regmatch_t *);
|
||||
static void do_regexpindex(const char *, regex_t *, regmatch_t *);
|
||||
static void do_regexp(const char *, regex_t *, const char *, regmatch_t *);
|
||||
static void add_sub(int, const char *, regex_t *, regmatch_t *);
|
||||
static void add_sub(size_t, const char *, regex_t *, regmatch_t *);
|
||||
static void add_replace(const char *, regex_t *, const char *, regmatch_t *);
|
||||
#define addconstantstring(s) addchars((s), sizeof(s)-1)
|
||||
|
||||
@ -273,7 +273,7 @@ exit_regerror(er, re)
|
||||
|
||||
static void
|
||||
add_sub(n, string, re, pm)
|
||||
int n;
|
||||
size_t n;
|
||||
const char *string;
|
||||
regex_t *re;
|
||||
regmatch_t *pm;
|
||||
@ -522,18 +522,12 @@ doesyscmd(cmd)
|
||||
{
|
||||
int p[2];
|
||||
pid_t pid, cpid;
|
||||
char *argv[4];
|
||||
int cc;
|
||||
int status;
|
||||
|
||||
/* Follow gnu m4 documentation: first flush buffers. */
|
||||
fflush(NULL);
|
||||
|
||||
argv[0] = "sh";
|
||||
argv[1] = "-c";
|
||||
argv[2] = (char *)cmd;
|
||||
argv[3] = NULL;
|
||||
|
||||
/* Just set up standard output, share stderr and stdin with m4 */
|
||||
if (pipe(p) == -1)
|
||||
err(1, "bad pipe");
|
||||
@ -545,7 +539,7 @@ doesyscmd(cmd)
|
||||
(void) close(p[0]);
|
||||
(void) dup2(p[1], 1);
|
||||
(void) close(p[1]);
|
||||
execv(_PATH_BSHELL, argv);
|
||||
execl(_PATH_BSHELL, "sh", "-c", cmd, NULL);
|
||||
exit(1);
|
||||
default:
|
||||
/* Read result in two stages, since m4's buffer is
|
||||
|
@ -80,14 +80,13 @@ int maxout;
|
||||
FILE *active; /* active output file pointer */
|
||||
int ilevel = 0; /* input file stack pointer */
|
||||
int oindex = 0; /* diversion index.. */
|
||||
char *null = ""; /* as it says.. just a null.. */
|
||||
char *m4wraps = ""; /* m4wrap string default.. */
|
||||
const char *null = ""; /* as it says.. just a null.. */
|
||||
const char *m4wraps = ""; /* m4wrap string default.. */
|
||||
char lquote[MAXCCHARS+1] = {LQUOTE}; /* left quote character (`) */
|
||||
char rquote[MAXCCHARS+1] = {RQUOTE}; /* right quote character (') */
|
||||
char scommt[MAXCCHARS+1] = {SCOMMT}; /* start character for comment */
|
||||
char ecommt[MAXCCHARS+1] = {ECOMMT}; /* end character for comment */
|
||||
int synccpp; /* Line synchronisation for C preprocessor */
|
||||
int chscratch; /* Scratch space for gpbc() macro */
|
||||
|
||||
struct keyblk keywrds[] = { /* m4 keywords to be installed */
|
||||
{ "include", INCLTYPE },
|
||||
@ -476,14 +475,14 @@ macro()
|
||||
|
||||
default:
|
||||
if (LOOK_AHEAD(t, scommt)) {
|
||||
char *p;
|
||||
for (p = scommt; *p; p++)
|
||||
chrsave(*p);
|
||||
char *pc;
|
||||
for (pc = scommt; *pc; pc++)
|
||||
chrsave(*pc);
|
||||
for(;;) {
|
||||
t = gpbc();
|
||||
if (LOOK_AHEAD(t, ecommt)) {
|
||||
for (p = ecommt; *p; p++)
|
||||
chrsave(*p);
|
||||
for (pc = ecommt; *pc; pc++)
|
||||
chrsave(*pc);
|
||||
break;
|
||||
}
|
||||
if (t == EOF)
|
||||
@ -574,7 +573,7 @@ initkwds()
|
||||
p->nxtptr = hashtab[h % HASHSIZE];
|
||||
hashtab[h % HASHSIZE] = p;
|
||||
p->name = xstrdup(keywrds[i].knam);
|
||||
p->defn = null;
|
||||
p->defn = xstrdup(null);
|
||||
p->hv = h;
|
||||
p->type = keywrds[i].ktyp & TYPEMASK;
|
||||
if ((keywrds[i].ktyp & NOARGS) == 0)
|
||||
@ -595,7 +594,7 @@ builtin_type(key)
|
||||
return -1;
|
||||
}
|
||||
|
||||
char *
|
||||
const char *
|
||||
builtin_realname(n)
|
||||
int n;
|
||||
{
|
||||
|
@ -145,7 +145,7 @@ struct ndblock { /* hastable structure */
|
||||
#define nil ((ndptr) 0)
|
||||
|
||||
struct keyblk {
|
||||
char *knam; /* keyword name */
|
||||
const char *knam; /* keyword name */
|
||||
int ktyp; /* keyword type */
|
||||
};
|
||||
|
||||
@ -166,13 +166,9 @@ struct input_file {
|
||||
/*
|
||||
* macros for readibility and/or speed
|
||||
*
|
||||
* gpbc() - get a possibly pushed-back character
|
||||
* pushf() - push a call frame entry onto stack
|
||||
* pushs() - push a string pointer onto stack
|
||||
*/
|
||||
#define gpbc() (bp > bufbase) ? (*--bp ? (*bp & 0xFF) : EOF) : \
|
||||
((chscratch = obtain_char(infile+ilevel)) == '\n' && \
|
||||
++inlineno[ilevel], chscratch)
|
||||
#define pushf(x) \
|
||||
do { \
|
||||
if (++sp == STACKMAX) \
|
||||
|
@ -111,7 +111,7 @@ pbstr(s)
|
||||
size_t n;
|
||||
|
||||
n = strlen(s);
|
||||
while (endpbb - bp <= n)
|
||||
while ((size_t)(endpbb - bp) <= n)
|
||||
enlarge_bufspace();
|
||||
while (n > 0)
|
||||
*bp++ = s[--n];
|
||||
@ -236,7 +236,7 @@ getdiv(n)
|
||||
|
||||
void
|
||||
onintr(signo)
|
||||
int signo;
|
||||
int signo __unused;
|
||||
{
|
||||
#define intrmessage "m4: interrupted.\n"
|
||||
write(STDERR_FILENO, intrmessage, sizeof(intrmessage)-1);
|
||||
@ -375,6 +375,6 @@ dump_buffer(f, m)
|
||||
{
|
||||
char *s;
|
||||
|
||||
for (s = bp; s-buf > m;)
|
||||
for (s = bp; s - buf > (int)m;)
|
||||
fputc(*--s, f);
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <stdio.h>
|
||||
#include <err.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "mdef.h"
|
||||
#include "stdd.h"
|
||||
#include "extern.h"
|
||||
|
Loading…
Reference in New Issue
Block a user