More cleanups: (#53)

- sprinkle const
- add a macro (setptr) that cheats const to temporarily NUL terminate strings
  remove casts from allocations
- use strdup instead of strlen+strcpy
- use x = malloc(sizeof(*x)) instead of x = malloc(sizeof(type of *x)))
- add -Wcast-qual (and casts through unitptr_t in the two macros we
  cheat (xfree, setptr)).
This commit is contained in:
zoulasc 2019-10-24 09:40:15 -04:00 committed by Arnold Robbins
parent 1633ba1c88
commit 6589208eaf
9 changed files with 98 additions and 96 deletions

9
awk.h
View File

@ -30,7 +30,12 @@ typedef double Awkfloat;
typedef unsigned char uschar;
#define xfree(a) { if ((a) != NULL) { free((void *) (a)); (a) = NULL; } }
#define xfree(a) { if ((a) != NULL) { free((void *)(intptr_t)(a)); (a) = NULL; } }
/*
* We sometimes cheat writing read-only pointers to NUL-terminate them
* and then put back the original value
*/
#define setptr(ptr, a) (*(char *)(intptr_t)(ptr)) = (a)
#define NN(p) ((p) ? (p) : "(null)") /* guaranteed non-null for dprintf
*/
@ -70,7 +75,7 @@ extern char inputFS[]; /* FS at time of input, for field splitting */
extern int dbg;
extern char *patbeg; /* beginning of pattern matched */
extern const char *patbeg; /* beginning of pattern matched */
extern int patlen; /* length of pattern matched. set in b.c */
/* Cell: all information about a variable or constant */

68
b.c
View File

@ -61,19 +61,19 @@ int maxsetvec = 0;
int rtok; /* next token in current re */
int rlxval;
static uschar *rlxstr;
static uschar *prestr; /* current position in current re */
static uschar *lastre; /* origin of last re */
static uschar *lastatom; /* origin of last Atom */
static uschar *starttok;
static uschar *basestr; /* starts with original, replaced during
static const uschar *rlxstr;
static const uschar *prestr; /* current position in current re */
static const uschar *lastre; /* origin of last re */
static const uschar *lastatom; /* origin of last Atom */
static const uschar *starttok;
static const uschar *basestr; /* starts with original, replaced during
repetition processing */
static uschar *firstbasestr;
static const uschar *firstbasestr;
static int setcnt;
static int poscnt;
char *patbeg;
const char *patbeg;
int patlen;
#define NFA 128 /* cache this many dynamic fa's */
@ -185,7 +185,7 @@ fa *mkdfa(const char *s, int anchor) /* does the real work of making a dfa */
Node *p, *p1;
fa *f;
firstbasestr = (uschar *) s;
firstbasestr = (const uschar *) s;
basestr = firstbasestr;
p = reparse(s);
p1 = op2(CAT, op2(STAR, op2(ALL, NIL, NIL), NIL), p);
@ -195,7 +195,7 @@ fa *mkdfa(const char *s, int anchor) /* does the real work of making a dfa */
poscnt = 0;
penter(p1); /* enter parent pointers and leaf indices */
if ((f = (fa *) calloc(1, sizeof(fa) + poscnt*sizeof(rrow))) == NULL)
if ((f = calloc(1, sizeof(fa) + poscnt * sizeof(rrow))) == NULL)
overflo(__func__);
f->accept = poscnt-1; /* penter has computed number of positions in re */
cfoll(f, p1); /* set up follow sets */
@ -295,13 +295,13 @@ void freetr(Node *p) /* free parse tree */
/* in the parsing of regular expressions, metacharacters like . have */
/* to be seen literally; \056 is not a metacharacter. */
int hexstr(uschar **pp) /* find and eval hex string at pp, return new p */
int hexstr(const uschar **pp) /* find and eval hex string at pp, return new p */
{ /* only pick up one 8-bit byte (2 chars) */
uschar *p;
const uschar *p;
int n = 0;
int i;
for (i = 0, p = (uschar *) *pp; i < 2 && isxdigit(*p); i++, p++) {
for (i = 0, p = *pp; i < 2 && isxdigit(*p); i++, p++) {
if (isdigit(*p))
n = 16 * n + *p - '0';
else if (*p >= 'a' && *p <= 'f')
@ -309,16 +309,16 @@ int hexstr(uschar **pp) /* find and eval hex string at pp, return new p */
else if (*p >= 'A' && *p <= 'F')
n = 16 * n + *p - 'A' + 10;
}
*pp = (uschar *) p;
*pp = p;
return n;
}
#define isoctdigit(c) ((c) >= '0' && (c) <= '7') /* multiple use of arg */
int quoted(uschar **pp) /* pick up next thing after a \\ */
int quoted(const uschar **pp) /* pick up next thing after a \\ */
/* and increment *pp */
{
uschar *p = *pp;
const uschar *p = *pp;
int c;
if ((c = *p++) == 't')
@ -356,8 +356,8 @@ int quoted(uschar **pp) /* pick up next thing after a \\ */
char *cclenter(const char *argp) /* add a character class */
{
int i, c, c2;
uschar *p = (uschar *) argp;
uschar *op, *bp;
const uschar *op, *p = (const uschar *) argp;
uschar *bp;
static uschar *buf = NULL;
static int bufsz = 100;
@ -516,7 +516,7 @@ void follow(Node *v) /* collects leaves that can follow v into setvec */
int member(int c, const char *sarg) /* is c in s? */
{
uschar *s = (uschar *) sarg;
const uschar *s = (const uschar *) sarg;
while (*s)
if (c == *s++)
@ -527,7 +527,7 @@ int member(int c, const char *sarg) /* is c in s? */
int match(fa *f, const char *p0) /* shortest match ? */
{
int s, ns;
uschar *p = (uschar *) p0;
const uschar *p = (const uschar *) p0;
s = f->initstat;
assert (s < f->state_count);
@ -549,13 +549,13 @@ int match(fa *f, const char *p0) /* shortest match ? */
int pmatch(fa *f, const char *p0) /* longest match, for sub */
{
int s, ns;
uschar *p = (uschar *) p0;
uschar *q;
const uschar *p = (const uschar *) p0;
const uschar *q;
s = f->initstat;
assert(s < f->state_count);
patbeg = (char *)p;
patbeg = (const char *)p;
patlen = -1;
do {
q = p;
@ -572,7 +572,7 @@ int pmatch(fa *f, const char *p0) /* longest match, for sub */
if (s == 1) { /* no transition */
if (patlen >= 0) {
patbeg = (char *) p;
patbeg = (const char *) p;
return(1);
}
else
@ -582,7 +582,7 @@ int pmatch(fa *f, const char *p0) /* longest match, for sub */
if (f->out[s])
patlen = q-p-1; /* don't count $ */
if (patlen >= 0) {
patbeg = (char *) p;
patbeg = (const char *) p;
return(1);
}
nextin:
@ -594,13 +594,13 @@ int pmatch(fa *f, const char *p0) /* longest match, for sub */
int nematch(fa *f, const char *p0) /* non-empty match, for sub */
{
int s, ns;
uschar *p = (uschar *) p0;
uschar *q;
const uschar *p = (const uschar *) p0;
const uschar *q;
s = f->initstat;
assert(s < f->state_count);
patbeg = (char *)p;
patbeg = (const char *)p;
patlen = -1;
while (*p) {
q = p;
@ -614,7 +614,7 @@ int nematch(fa *f, const char *p0) /* non-empty match, for sub */
s = cgoto(f, s, *q);
if (s == 1) { /* no transition */
if (patlen > 0) {
patbeg = (char *) p;
patbeg = (const char *) p;
return(1);
} else
goto nnextin; /* no nonempty match */
@ -623,7 +623,7 @@ int nematch(fa *f, const char *p0) /* non-empty match, for sub */
if (f->out[s])
patlen = q-p-1; /* don't count $ */
if (patlen > 0 ) {
patbeg = (char *) p;
patbeg = (const char *) p;
return(1);
}
nnextin:
@ -726,7 +726,7 @@ Node *reparse(const char *p) /* parses regular expression pointed to by p */
Node *np;
dprintf( ("reparse <%s>\n", p) );
lastre = prestr = (uschar *) p; /* prestr points to string to be parsed */
lastre = prestr = (const uschar *) p; /* prestr points to string to be parsed */
rtok = relex();
/* GNU compatibility: an empty regexp matches anything */
if (rtok == '\0') {
@ -766,12 +766,12 @@ Node *primary(void)
rtok = relex();
return (unary(op2(DOT, NIL, NIL)));
case CCL:
np = op2(CCL, NIL, (Node*) cclenter((char *) rlxstr));
np = op2(CCL, NIL, (Node*) cclenter((const char *) rlxstr));
lastatom = starttok;
rtok = relex();
return (unary(np));
case NCCL:
np = op2(NCCL, NIL, (Node *) cclenter((char *) rlxstr));
np = op2(NCCL, NIL, (Node *) cclenter((const char *) rlxstr));
lastatom = starttok;
rtok = relex();
return (unary(np));
@ -911,7 +911,7 @@ replace_repeat(const uschar *reptok, int reptoklen, const uschar *atom,
int init_q = (firstnum==0); /* first added char will be ? */
int n_q_reps = secondnum-firstnum; /* m>n, so reduce until {1,m-n} left */
int prefix_length = reptok - basestr; /* prefix includes first rep */
int suffix_length = strlen((char *) reptok) - reptoklen; /* string after rep specifier */
int suffix_length = strlen((const char *) reptok) - reptoklen; /* string after rep specifier */
int size = prefix_length + suffix_length;
if (firstnum > 1) { /* add room for reps 2 through firstnum */

6
lex.c
View File

@ -173,7 +173,7 @@ int yylex(void)
static char *buf = NULL;
static int bufsize = 5; /* BUG: setting this small causes core dump! */
if (buf == NULL && (buf = (char *) malloc(bufsize)) == NULL)
if (buf == NULL && (buf = malloc(bufsize)) == NULL)
FATAL( "out of space in yylex" );
if (sc) {
sc = 0;
@ -363,7 +363,7 @@ int string(void)
static char *buf = NULL;
static int bufsz = 500;
if (buf == NULL && (buf = (char *) malloc(bufsz)) == NULL)
if (buf == NULL && (buf = malloc(bufsz)) == NULL)
FATAL("out of space for strings");
for (bp = buf; (c = input()) != '"'; ) {
if (!adjbuf(&buf, &bufsz, bp-buf+2, 500, &bp, "string"))
@ -510,7 +510,7 @@ int regexpr(void)
static int bufsz = 500;
char *bp;
if (buf == NULL && (buf = (char *) malloc(bufsz)) == NULL)
if (buf == NULL && (buf = malloc(bufsz)) == NULL)
FATAL("out of space for rex expr");
bp = buf;
for ( ; (c = input()) != '/' && c != 0; ) {

18
lib.c
View File

@ -57,10 +57,10 @@ static Cell dollar1 = { OCELL, CFLD, NULL, "", 0.0, FLD|STR|DONTFREE };
void recinit(unsigned int n)
{
if ( (record = (char *) malloc(n)) == NULL
|| (fields = (char *) malloc(n+1)) == NULL
|| (fldtab = (Cell **) malloc((nfields+2) * sizeof(Cell *))) == NULL
|| (fldtab[0] = (Cell *) malloc(sizeof(Cell))) == NULL )
if ( (record = malloc(n)) == NULL
|| (fields = malloc(n+1)) == NULL
|| (fldtab = calloc(nfields+2, sizeof(*fldtab))) == NULL
|| (fldtab[0] = malloc(sizeof(**fldtab))) == NULL)
FATAL("out of space for $0 and fields");
*record = '\0';
*fldtab[0] = dollar0;
@ -75,7 +75,7 @@ void makefields(int n1, int n2) /* create $n1..$n2 inclusive */
int i;
for (i = n1; i <= n2; i++) {
fldtab[i] = (Cell *) malloc(sizeof (struct Cell));
fldtab[i] = malloc(sizeof(**fldtab));
if (fldtab[i] == NULL)
FATAL("out of space in makefields %d", i);
*fldtab[i] = dollar1;
@ -215,7 +215,7 @@ int readrec(char **pbuf, int *pbufsize, FILE *inf) /* read one record into buf *
fa *pfa = makedfa(rs, 1);
found = fnematch(pfa, inf, &buf, &bufsize, recsize);
if (found)
*patbeg = 0;
setptr(patbeg, '\0');
} else {
if ((sep = *rs) == 0) {
sep = '\n';
@ -304,7 +304,7 @@ void fldbld(void) /* create fields from current record */
n = strlen(r);
if (n > fieldssize) {
xfree(fields);
if ((fields = (char *) malloc(n+2)) == NULL) /* possibly 2 final \0s */
if ((fields = malloc(n+2)) == NULL) /* possibly 2 final \0s */
FATAL("out of space for fields in fldbld %d", n);
fieldssize = n;
}
@ -447,7 +447,7 @@ void growfldtab(int n) /* make new fields up to at least $n */
nf = n;
s = (nf+1) * (sizeof (struct Cell *)); /* freebsd: how much do we need? */
if (s / sizeof(struct Cell *) - 1 == nf) /* didn't overflow */
fldtab = (Cell **) realloc(fldtab, s);
fldtab = realloc(fldtab, s);
else /* overflow sizeof int */
xfree(fldtab); /* make it null */
if (fldtab == NULL)
@ -467,7 +467,7 @@ int refldbld(const char *rec, const char *fs) /* build fields from reg expr in F
n = strlen(rec);
if (n > fieldssize) {
xfree(fields);
if ((fields = (char *) malloc(n+1)) == NULL)
if ((fields = malloc(n+1)) == NULL)
FATAL("out of space for fields in refldbld %d", n);
fieldssize = n;
}

View File

@ -145,8 +145,7 @@ int main(int argc, char *argv[])
/* fprintf(stderr, "maketab funny token %d %s ignored\n", tok, buf); */
continue;
}
names[tok-FIRSTTOKEN] = (char *) malloc(strlen(name)+1);
strcpy(names[tok-FIRSTTOKEN], name);
names[tok-FIRSTTOKEN] = strdup(name);
printf("\t(char *) \"%s\",\t/* %d */\n", name, tok);
i++;
}

View File

@ -33,7 +33,7 @@ Node *nodealloc(int n)
{
Node *x;
x = (Node *) malloc(sizeof(Node) + (n-1)*sizeof(Node *));
x = malloc(sizeof(*x) + (n-1) * sizeof(x));
if (x == NULL)
FATAL("out of space in nodealloc");
x->nnext = NULL;

View File

@ -43,8 +43,8 @@ extern fa *mkdfa(const char *, int);
extern int makeinit(fa *, int);
extern void penter(Node *);
extern void freetr(Node *);
extern int hexstr(uschar **);
extern int quoted(uschar **);
extern int hexstr(const uschar **);
extern int quoted(const uschar **);
extern char *cclenter(const char *);
extern void overflo(const char *) __attribute__((__noreturn__));
extern void cfoll(fa *, Node *);

61
run.c
View File

@ -113,8 +113,8 @@ int adjbuf(char **pbuf, int *psiz, int minlen, int quantum, char **pbptr,
/* round up to next multiple of quantum */
if (rminlen)
minlen += quantum - rminlen;
tbuf = (char *) realloc(*pbuf, minlen);
dprintf( ("adjbuf %s: %d %d (pbuf=%p, tbuf=%p)\n", whatrtn, *psiz, minlen, (void *) *pbuf, (void *) tbuf) );
tbuf = realloc(*pbuf, minlen);
dprintf( ("adjbuf %s: %d %d (pbuf=%p, tbuf=%p)\n", whatrtn, *psiz, minlen, *pbuf, tbuf) );
if (tbuf == NULL) {
if (whatrtn)
FATAL("out of memory in %s", whatrtn);
@ -236,7 +236,7 @@ Cell *call(Node **a, int n) /* function call. very kludgy and fragile */
if (!isfcn(fcn))
FATAL("calling undefined function %s", s);
if (frame == NULL) {
fp = frame = (struct Frame *) calloc(nframe += 100, sizeof(struct Frame));
fp = frame = calloc(nframe += 100, sizeof(*frame));
if (frame == NULL)
FATAL("out of space for stack frames calling %s", s);
}
@ -270,8 +270,7 @@ Cell *call(Node **a, int n) /* function call. very kludgy and fragile */
fp++; /* now ok to up frame */
if (fp >= frame + nframe) {
int dfp = fp - frame; /* old index */
frame = (struct Frame *)
realloc((char *) frame, (nframe += 100) * sizeof(struct Frame));
frame = realloc(frame, (nframe += 100) * sizeof(*frame));
if (frame == NULL)
FATAL("out of space for stack frames in %s", s);
fp = frame + dfp;
@ -404,7 +403,7 @@ Cell *awkgetline(Node **a, int n) /* get next line from specific input */
int bufsize = recsize;
int mode;
if ((buf = (char *) malloc(bufsize)) == NULL)
if ((buf = malloc(bufsize)) == NULL)
FATAL("out of memory in getline");
fflush(stdout); /* in case someone is waiting for a prompt */
@ -472,7 +471,7 @@ Cell *array(Node **a, int n) /* a[0] is symtab, a[1] is list of subscripts */
int bufsz = recsize;
int nsub;
if ((buf = (char *) malloc(bufsz)) == NULL)
if ((buf = malloc(bufsz)) == NULL)
FATAL("out of memory in array");
x = execute(a[0]); /* Cell* for symbol table */
@ -525,7 +524,7 @@ Cell *awkdelete(Node **a, int n) /* a[0] is symtab, a[1] is list of subscripts *
} else {
int bufsz = recsize;
char *buf;
if ((buf = (char *) malloc(bufsz)) == NULL)
if ((buf = malloc(bufsz)) == NULL)
FATAL("out of memory in adelete");
buf[0] = 0;
for (np = a[1]; np; np = np->nnext) {
@ -564,7 +563,7 @@ Cell *intest(Node **a, int n) /* a[0] is index (list), a[1] is symtab */
ap->tval |= ARR;
ap->sval = (char *) makesymtab(NSYMTAB);
}
if ((buf = (char *) malloc(bufsz)) == NULL) {
if ((buf = malloc(bufsz)) == NULL) {
FATAL("out of memory in intest");
}
buf[0] = 0;
@ -714,7 +713,7 @@ Cell *gettemp(void) /* get a tempcell */
Cell *x;
if (!tmps) {
tmps = (Cell *) calloc(100, sizeof(Cell));
tmps = calloc(100, sizeof(*tmps));
if (!tmps)
FATAL("out of space for temporaries");
for (i = 1; i < 100; i++)
@ -850,7 +849,7 @@ int format(char **pbuf, int *pbufsize, const char *s, Node *a) /* printf-like co
os = s;
p = buf;
if ((fmt = (char *) malloc(fmtsz)) == NULL)
if ((fmt = malloc(fmtsz)) == NULL)
FATAL("out of memory in format()");
while (*s) {
adjbuf(&buf, &bufsize, MAXNUMSIZE+1+p-buf, recsize, &p, "format1");
@ -991,7 +990,7 @@ Cell *awksprintf(Node **a, int n) /* sprintf(a[0]) */
char *buf;
int bufsz=3*recsize;
if ((buf = (char *) malloc(bufsz)) == NULL)
if ((buf = malloc(bufsz)) == NULL)
FATAL("out of memory in awksprintf");
y = a[0]->nnext;
x = execute(a[0]);
@ -1014,7 +1013,7 @@ Cell *awkprintf(Node **a, int n) /* printf */
int len;
int bufsz=3*recsize;
if ((buf = (char *) malloc(bufsz)) == NULL)
if ((buf = malloc(bufsz)) == NULL)
FATAL("out of memory in awkprintf");
y = a[0]->nnext;
x = execute(a[0]);
@ -1257,10 +1256,10 @@ Cell *dopa2(Node **a, int n) /* a[0], a[1] { a[2] } */
Cell *split(Node **a, int nnn) /* split(a[0], a[1], a[2]); a[3] is type */
{
Cell *x = NULL, *y, *ap;
char *s, *origs;
const char *s, *origs, *t;
char *fs = NULL, *origfs = NULL;
int sep;
char *t, temp, num[50];
char temp, num[50];
int n, tempstat, arg3type;
y = execute(a[0]); /* source string */
@ -1305,12 +1304,12 @@ Cell *split(Node **a, int nnn) /* split(a[0], a[1], a[2]); a[3] is type */
n++;
sprintf(num, "%d", n);
temp = *patbeg;
*patbeg = '\0';
setptr(patbeg, '\0');
if (is_number(s))
setsymtab(num, s, atof(s), STR|NUM, (Array *) ap->sval);
else
setsymtab(num, s, 0.0, STR, (Array *) ap->sval);
*patbeg = temp;
setptr(patbeg, temp);
s = patbeg + patlen;
if (*(patbeg+patlen-1) == 0 || *s == 0) {
n++;
@ -1343,13 +1342,13 @@ Cell *split(Node **a, int nnn) /* split(a[0], a[1], a[2]); a[3] is type */
s++;
while (*s!=' ' && *s!='\t' && *s!='\n' && *s!='\0');
temp = *s;
*s = '\0';
setptr(s, '\0');
sprintf(num, "%d", n);
if (is_number(t))
setsymtab(num, t, atof(t), STR|NUM, (Array *) ap->sval);
else
setsymtab(num, t, 0.0, STR, (Array *) ap->sval);
*s = temp;
setptr(s, temp);
if (*s != 0)
s++;
}
@ -1372,21 +1371,21 @@ Cell *split(Node **a, int nnn) /* split(a[0], a[1], a[2]); a[3] is type */
while (*s != sep && *s != '\n' && *s != '\0')
s++;
temp = *s;
*s = '\0';
setptr(s, '\0');
sprintf(num, "%d", n);
if (is_number(t))
setsymtab(num, t, atof(t), STR|NUM, (Array *) ap->sval);
else
setsymtab(num, t, 0.0, STR, (Array *) ap->sval);
*s = temp;
setptr(s, temp);
if (*s++ == 0)
break;
}
}
tempfree(ap);
tempfree(y);
free(origs);
free(origfs);
xfree(origs);
xfree(origfs);
x = gettemp();
x->tval = NUM;
x->fval = n;
@ -1828,13 +1827,13 @@ void flush_all(void)
fflush(files[i].fp);
}
void backsub(char **pb_ptr, char **sptr_ptr);
void backsub(char **pb_ptr, const char **sptr_ptr);
Cell *sub(Node **a, int nnn) /* substitute command */
{
char *sptr, *pb, *q;
const char *sptr, *q;
Cell *x, *y, *result;
char *t, *buf;
char *t, *buf, *pb;
fa *pfa;
int bufsz = recsize;
@ -1893,13 +1892,14 @@ Cell *sub(Node **a, int nnn) /* substitute command */
Cell *gsub(Node **a, int nnn) /* global substitute */
{
Cell *x, *y;
char *rptr, *sptr, *t, *pb, *q;
char *rptr, *pb;
const char *q, *t, *sptr;
char *buf;
fa *pfa;
int mflag, tempstat, num;
int bufsz = recsize;
if ((buf = (char *) malloc(bufsz)) == NULL)
if ((buf = malloc(bufsz)) == NULL)
FATAL("out of memory in gsub");
mflag = 0; /* if mflag == 0, can replace empty string */
num = 0;
@ -1991,9 +1991,10 @@ Cell *gsub(Node **a, int nnn) /* global substitute */
return(x);
}
void backsub(char **pb_ptr, char **sptr_ptr) /* handle \\& variations */
void backsub(char **pb_ptr, const char **sptr_ptr) /* handle \\& variations */
{ /* sptr[0] == '\\' */
char *pb = *pb_ptr, *sptr = *sptr_ptr;
char *pb = *pb_ptr;
const char *sptr = *sptr_ptr;
if (sptr[1] == '\\') {
if (sptr[2] == '\\' && sptr[3] == '&') { /* \\\& -> \& */

23
tran.c
View File

@ -164,8 +164,8 @@ Array *makesymtab(int n) /* make a new symbol table */
Array *ap;
Cell **tp;
ap = (Array *) malloc(sizeof(Array));
tp = (Cell **) calloc(n, sizeof(Cell *));
ap = malloc(sizeof(*ap));
tp = calloc(n, sizeof(*tp));
if (ap == NULL || tp == NULL)
FATAL("out of space in makesymtab");
ap->nelem = 0;
@ -235,7 +235,7 @@ Cell *setsymtab(const char *n, const char *s, Awkfloat f, unsigned t, Array *tp)
(void*)p, NN(p->nval), NN(p->sval), p->fval, p->tval) );
return(p);
}
p = (Cell *) malloc(sizeof(Cell));
p = malloc(sizeof(*p));
if (p == NULL)
FATAL("out of space for symbol table at %s", n);
p->nval = tostring(n);
@ -270,7 +270,7 @@ void rehash(Array *tp) /* rehash items in small table into big one */
Cell *cp, *op, **np;
nsz = GROWTAB * tp->size;
np = (Cell **) calloc(nsz, sizeof(Cell *));
np = calloc(nsz, sizeof(*np));
if (np == NULL) /* can't do it, but can keep running. */
return; /* someone else will run out later. */
for (i = 0; i < tp->size; i++) {
@ -359,7 +359,7 @@ char *setsval(Cell *vp, const char *s) /* set string val of a Cell */
fldno = atoi(vp->nval);
if (fldno > *NF)
newfld(fldno);
dprintf( ("setting field %d to %s (%p)\n", fldno, s, (void *) s) );
dprintf( ("setting field %d to %s (%p)\n", fldno, s, s) );
} else if (isrec(vp)) {
donefld = 0; /* mark $1... invalid */
donerec = 1;
@ -376,7 +376,7 @@ char *setsval(Cell *vp, const char *s) /* set string val of a Cell */
vp->fmt = NULL;
setfree(vp);
dprintf( ("setsval %p: %s = \"%s (%p) \", t=%o r,f=%d,%d\n",
(void*)vp, NN(vp->nval), t, (void *) t, vp->tval, donerec, donefld) );
(void*)vp, NN(vp->nval), t, t, vp->tval, donerec, donefld) );
vp->sval = t;
if (&vp->fval == NF) {
donerec = 0; /* mark $0 invalid */
@ -490,7 +490,7 @@ static char *get_str_val(Cell *vp, char **fmt) /* get string val of a Cel
}
done:
dprintf( ("getsval %p: %s = \"%s (%p)\", t=%o\n",
(void*)vp, NN(vp->nval), vp->sval, (void *) vp->sval, vp->tval) );
(void*)vp, NN(vp->nval), vp->sval, vp->sval, vp->tval) );
return(vp->sval);
}
@ -507,12 +507,9 @@ char *getpssval(Cell *vp) /* get string val of a Cell for print */
char *tostring(const char *s) /* make a copy of string s */
{
char *p;
p = (char *) malloc(strlen(s)+1);
char *p = strdup(s);
if (p == NULL)
FATAL("out of space in tostring on %s", s);
strcpy(p, s);
return(p);
}
@ -536,10 +533,10 @@ char *qstring(const char *is, int delim) /* collect string up to next delim */
{
const char *os = is;
int c, n;
uschar *s = (uschar *) is;
const uschar *s = (const uschar *) is;
uschar *buf, *bp;
if ((buf = (uschar *) malloc(strlen(is)+3)) == NULL)
if ((buf = malloc(strlen(is)+3)) == NULL)
FATAL( "out of space in qstring(%s)", s);
for (bp = buf; (c = *s) != delim; s++) {
if (c == '\n')