aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2024-01-22 07:45:31 +0200
committerArnold D. Robbins <arnold@skeeve.com>2024-01-22 07:45:31 +0200
commitee8484a4a2cb6ac3b263f4da0fe83cabf8683ddb (patch)
tree4fa074644726706f0ff006f0ffa448ed436bce54
parent908be9c222c0b7da4bcc3b8724ebb11996993a69 (diff)
downloadone-true-awk-ee8484a4a2cb6ac3b263f4da0fe83cabf8683ddb.tar.gz
Restore ability to compile with g++.
-rw-r--r--FIXES4
-rw-r--r--b.c28
-rw-r--r--main.c2
-rw-r--r--run.c5
4 files changed, 21 insertions, 18 deletions
diff --git a/FIXES b/FIXES
index 21efda5..3b05925 100644
--- a/FIXES
+++ b/FIXES
@@ -25,6 +25,10 @@ THIS SOFTWARE.
This file lists all bug fixes, changes, etc., made since the
second edition of the AWK book was published in September 2023.
+Jan 22, 2024:
+ Restore the ability to compile with g++. Thanks to
+ Arnold Robbins.
+
Dec 24, 2023:
matchop dereference after free problem fix when the first
argument is a function call. thanks to Oguz Ismail Uysal.
diff --git a/b.c b/b.c
index db96d5f..0ac7b9f 100644
--- a/b.c
+++ b/b.c
@@ -116,7 +116,7 @@ static int entry_cmp(const void *l, const void *r);
static int get_gototab(fa*, int, int);
static int set_gototab(fa*, int, int, int);
static void clear_gototab(fa*, int);
-extern int u8_rune(int *, const uschar *);
+extern int u8_rune(int *, const char *);
static int *
intalloc(size_t n, const char *f)
@@ -416,7 +416,7 @@ int *cclenter(const char *argp) /* add a character class */
FATAL("out of space for character class [%.10s...] 1", p);
bp = buf;
for (i = 0; *p != 0; ) {
- n = u8_rune(&c, p);
+ n = u8_rune(&c, (const char *) p);
p += n;
if (c == '\\') {
c = quoted(&p);
@@ -424,7 +424,7 @@ int *cclenter(const char *argp) /* add a character class */
if (*p != 0) {
c = bp[-1];
/* c2 = *p++; */
- n = u8_rune(&c2, p);
+ n = u8_rune(&c2, (const char *) p);
p += n;
if (c2 == '\\')
c2 = quoted(&p); /* BUG: sets p, has to be u8 size */
@@ -618,7 +618,7 @@ static int get_gototab(fa *f, int state, int ch) /* hide gototab inplementation
key.ch = ch;
key.state = 0; /* irrelevant */
- item = bsearch(& key, f->gototab[state].entries,
+ item = (gtte *) bsearch(& key, f->gototab[state].entries,
f->gototab[state].inuse, sizeof(gtte),
entry_cmp);
@@ -662,7 +662,7 @@ static int set_gototab(fa *f, int state, int ch, int val) /* hide gototab inplem
key.ch = ch;
key.state = 0; /* irrelevant */
- item = bsearch(& key, f->gototab[state].entries,
+ item = (gtte *) bsearch(& key, f->gototab[state].entries,
f->gototab[state].inuse, sizeof(gtte),
entry_cmp);
@@ -710,7 +710,7 @@ int match(fa *f, const char *p0) /* shortest match ? */
return(1);
do {
/* assert(*p < NCHARS); */
- n = u8_rune(&rune, p);
+ n = u8_rune(&rune, (const char *) p);
if ((ns = get_gototab(f, s, rune)) != 0)
s = ns;
else
@@ -743,7 +743,7 @@ int pmatch(fa *f, const char *p0) /* longest match, for sub */
if (f->out[s]) /* final state */
patlen = q-p;
/* assert(*q < NCHARS); */
- n = u8_rune(&rune, q);
+ n = u8_rune(&rune, (const char *) q);
if ((ns = get_gototab(f, s, rune)) != 0)
s = ns;
else
@@ -774,7 +774,7 @@ int pmatch(fa *f, const char *p0) /* longest match, for sub */
s = 2;
if (*p == 0)
break;
- n = u8_rune(&rune, p);
+ n = u8_rune(&rune, (const char *) p);
p += n;
} while (1); /* was *p++ */
return (0);
@@ -799,7 +799,7 @@ int nematch(fa *f, const char *p0) /* non-empty match, for sub */
if (f->out[s]) /* final state */
patlen = q-p;
/* assert(*q < NCHARS); */
- n = u8_rune(&rune, q);
+ n = u8_rune(&rune, (const char *) q);
if ((ns = get_gototab(f, s, rune)) != 0)
s = ns;
else
@@ -887,7 +887,7 @@ bool fnematch(fa *pfa, FILE *f, char **pbuf, int *pbufsize, int quantum)
}
}
- j += u8_rune(&c, (uschar *)j);
+ j += u8_rune(&c, j);
if ((ns = get_gototab(pfa, s, c)) != 0)
s = ns;
@@ -907,7 +907,7 @@ bool fnematch(fa *pfa, FILE *f, char **pbuf, int *pbufsize, int quantum)
break; /* best match found */
/* no match at origin i, next i and start over */
- i += u8_rune(&c, (uschar *)i);
+ i += u8_rune(&c, i);
if (c == 0)
break; /* no match */
j = i;
@@ -1229,8 +1229,6 @@ static int repeat(const uschar *reptok, int reptoklen, const uschar *atom,
return 0;
}
-extern int u8_rune(int *, const uschar *); /* run.c; should be in header file */
-
int relex(void) /* lexical analyzer for reparse */
{
int c, n;
@@ -1248,7 +1246,7 @@ int relex(void) /* lexical analyzer for reparse */
rescan:
starttok = prestr;
- if ((n = u8_rune(&rlxval, prestr)) > 1) {
+ if ((n = u8_rune(&rlxval, (const char *) prestr)) > 1) {
prestr += n;
starttok = prestr;
return CHAR;
@@ -1295,7 +1293,7 @@ rescan:
if (!adjbuf((char **) &buf, &bufsz, n, n, (char **) &bp, "relex1"))
FATAL("out of space for reg expr %.10s...", lastre);
for (; ; ) {
- if ((n = u8_rune(&rlxval, prestr)) > 1) {
+ if ((n = u8_rune(&rlxval, (const char *) prestr)) > 1) {
for (i = 0; i < n; i++)
*bp++ = *prestr++;
continue;
diff --git a/main.c b/main.c
index 58f1541..73af89e 100644
--- a/main.c
+++ b/main.c
@@ -22,7 +22,7 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
THIS SOFTWARE.
****************************************************************/
-const char *version = "version 20231228";
+const char *version = "version 20240122";
#define DEBUG
#include <stdio.h>
diff --git a/run.c b/run.c
index 098afbb..799e998 100644
--- a/run.c
+++ b/run.c
@@ -1300,7 +1300,8 @@ int format(char **pbuf, int *pbufsize, const char *s, Node *a) /* printf-like co
if (bs == NULL) { // invalid character
// use unicode invalid character, 0xFFFD
- bs = "\357\277\275";
+ static char invalid_char[] = "\357\277\275";
+ bs = invalid_char;
count = 3;
}
t = bs;
@@ -2448,7 +2449,7 @@ Cell *dosub(Node **a, int subop) /* sub and gsub */
start = getsval(x);
while (pmatch(pfa, start)) {
if (buf == NULL) {
- if ((pb = buf = malloc(bufsz)) == NULL)
+ if ((pb = buf = (char *) malloc(bufsz)) == NULL)
FATAL("out of memory in dosub");
tempstat = pfa->initstat;
pfa->initstat = 2;