From: millert Date: Mon, 3 Jun 2024 00:55:05 +0000 (+0000) Subject: Build with WARNINGS=Yes and fix resulting warnings. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=88689b4c913acc5e9faeb5344b3a42c16fde9497;p=openbsd Build with WARNINGS=Yes and fix resulting warnings. --- diff --git a/usr.bin/awk/Makefile b/usr.bin/awk/Makefile index ae4e3c2850a..54f62d00200 100644 --- a/usr.bin/awk/Makefile +++ b/usr.bin/awk/Makefile @@ -1,5 +1,6 @@ -# $OpenBSD: Makefile,v 1.18 2020/07/30 17:45:44 millert Exp $ +# $OpenBSD: Makefile,v 1.19 2024/06/03 00:55:05 millert Exp $ +WARNINGS=Yes PROG= awk SRCS= awkgram.tab.c lex.c b.c main.c parse.c proctab.c tran.c lib.c run.c LDADD= -lm diff --git a/usr.bin/awk/b.c b/usr.bin/awk/b.c index 82f65221667..53a36d27b63 100644 --- a/usr.bin/awk/b.c +++ b/usr.bin/awk/b.c @@ -1,4 +1,4 @@ -/* $OpenBSD: b.c,v 1.52 2024/05/04 22:59:21 millert Exp $ */ +/* $OpenBSD: b.c,v 1.53 2024/06/03 00:55:05 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -81,9 +81,6 @@ int patlen; fa *fatab[NFA]; int nfatab = 0; /* entries in fatab */ -extern int u8_nextlen(const char *s); - - /* utf-8 mechanism: For most of Awk, utf-8 strings just "work", since they look like @@ -117,7 +114,6 @@ 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 char *); static int * intalloc(size_t n, const char *f) @@ -347,7 +343,8 @@ 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(const uschar **pp, int max) /* find and eval hex string at pp, return new p */ +static int +hexstr(const uschar **pp, int max) /* find and eval hex string at pp, return new p */ { /* only pick up one 8-bit byte (2 chars) */ const uschar *p; int n = 0; diff --git a/usr.bin/awk/lex.c b/usr.bin/awk/lex.c index 4c7371de3bb..f2b7d09e60a 100644 --- a/usr.bin/awk/lex.c +++ b/usr.bin/awk/lex.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lex.c,v 1.32 2023/11/25 16:31:33 millert Exp $ */ +/* $OpenBSD: lex.c,v 1.33 2024/06/03 00:55:05 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -379,8 +379,6 @@ int yylex(void) } } -extern int runetochar(char *str, int c); - int string(void) { int c, n; diff --git a/usr.bin/awk/lib.c b/usr.bin/awk/lib.c index be752fb986a..ecd33d5edea 100644 --- a/usr.bin/awk/lib.c +++ b/usr.bin/awk/lib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib.c,v 1.57 2024/05/05 02:55:34 jsg Exp $ */ +/* $OpenBSD: lib.c,v 1.58 2024/06/03 00:55:05 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -35,8 +35,6 @@ THIS SOFTWARE. #include #include "awk.h" -extern int u8_nextlen(const char *s); - char EMPTY[] = { '\0' }; FILE *infile = NULL; bool innew; /* true = infile has not been read by readrec */ @@ -757,7 +755,7 @@ void WARNING(const char *fmt, ...) error(); } -void error() +void error(void) { extern Node *curnode; diff --git a/usr.bin/awk/proto.h b/usr.bin/awk/proto.h index 4c2fafd0825..0b578cdcc63 100644 --- a/usr.bin/awk/proto.h +++ b/usr.bin/awk/proto.h @@ -1,4 +1,4 @@ -/* $OpenBSD: proto.h,v 1.23 2023/11/22 01:01:21 millert Exp $ */ +/* $OpenBSD: proto.h,v 1.24 2024/06/03 00:55:05 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -205,4 +205,8 @@ extern Cell *gensub(Node **, int); extern FILE *popen(const char *, const char *); extern int pclose(FILE *); +extern int u8_nextlen(const char *s); +extern int u8_rune(int *, const char *); +extern int runetochar(char *str, int c); + extern const char *flags2str(int flags); diff --git a/usr.bin/awk/run.c b/usr.bin/awk/run.c index 14cc404a0ea..23bf3a9fabc 100644 --- a/usr.bin/awk/run.c +++ b/usr.bin/awk/run.c @@ -1,4 +1,4 @@ -/* $OpenBSD: run.c,v 1.86 2024/05/04 22:59:21 millert Exp $ */ +/* $OpenBSD: run.c,v 1.87 2024/06/03 00:55:05 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -600,7 +600,7 @@ Cell *intest(Node **a, int n) /* a[0] is index (list), a[1] is symtab */ /* is s the beginning of a valid utf-8 string? */ /* return length 1..4 if yes, 0 if no */ -int u8_isutf(const char *s) +static int u8_isutf(const char *s) { int n, ret; unsigned char c; @@ -671,7 +671,7 @@ int u8_nextlen(const char *s) } /* return number of utf characters or single non-utf bytes */ -int u8_strlen(const char *s) +static int u8_strlen(const char *s) { int i, len, n, totlen; unsigned char c; @@ -693,7 +693,7 @@ int u8_strlen(const char *s) } /* convert utf-8 char number in a string to its byte offset */ -int u8_char2byte(const char *s, int charnum) +static int u8_char2byte(const char *s, int charnum) { int n; int bytenum = 0; @@ -708,7 +708,7 @@ int u8_char2byte(const char *s, int charnum) } /* convert byte offset in s to utf-8 char number that starts there */ -int u8_byte2char(const char *s, int bytenum) +static int u8_byte2char(const char *s, int bytenum) { int i, len, b; int charnum = 0; /* BUG: what origin? */ @@ -1062,7 +1062,7 @@ Cell *sindex(Node **a, int nnn) /* index(a[0], a[1]) */ return(z); } -int has_utf8(char *s) /* return 1 if s contains any utf-8 (2 bytes or more) character */ +static int has_utf8(char *s) /* return 1 if s contains any utf-8 (2 bytes or more) character */ { int n; @@ -1248,13 +1248,13 @@ int format(char **pbuf, int *pbufsize, const char *s, Node *a) /* printf-like co if (prec > u8_strlen(t)) prec = u8_strlen(t); pad = wid>prec ? wid - prec : 0; // has to be >= 0 - int i, k, n; + int i, precb; if (ljust) { // print prec chars from t, then pad blanks - n = u8_char2byte(t, prec); - for (k = 0; k < n; k++) { - //putchar(t[k]); - *p++ = t[k]; + precb = u8_char2byte(t, prec); + for (i = 0; i < precb; i++) { + //putchar(t[i]); + *p++ = t[i]; } for (i = 0; i < pad; i++) { //printf(" "); @@ -1265,10 +1265,10 @@ int format(char **pbuf, int *pbufsize, const char *s, Node *a) /* printf-like co //printf(" "); *p++ = ' '; } - n = u8_char2byte(t, prec); - for (k = 0; k < n; k++) { - //putchar(t[k]); - *p++ = t[k]; + precb = u8_char2byte(t, prec); + for (i = 0; i < precb; i++) { + //putchar(t[i]); + *p++ = t[i]; } } *p = 0; @@ -1986,7 +1986,6 @@ static char *nawk_convert(const char *s, int (*fun_c)(int), size_t n = 0; wchar_t wc; const size_t sz = awk_mb_cur_max; - int unused; if (sz == 1) { buf = tostring(s); @@ -1999,15 +1998,9 @@ static char *nawk_convert(const char *s, int (*fun_c)(int), /* upper/lower character may be shorter/longer */ buf = tostringN(s, strlen(s) * sz + 1); - (void) mbtowc(NULL, NULL, 0); /* reset internal state */ - /* - * Reset internal state here too. - * Assign result to avoid a compiler warning. (Casting to void - * doesn't work.) - * Increment said variable to avoid a different warning. - */ - unused = wctomb(NULL, L'\0'); - unused++; + /* reset internal state */ + if (mbtowc(NULL, NULL, 0) == -1 || wctomb(NULL, L'\0') == -1) + FATAL("unable to reset character conversion state"); ps = s; pbuf = buf; diff --git a/usr.bin/awk/tran.c b/usr.bin/awk/tran.c index ba31583e980..315735bf7ea 100644 --- a/usr.bin/awk/tran.c +++ b/usr.bin/awk/tran.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tran.c,v 1.39 2024/05/04 22:59:21 millert Exp $ */ +/* $OpenBSD: tran.c,v 1.40 2024/06/03 00:55:05 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -644,7 +644,7 @@ const char *flags2str(int flags) if ((flags & flagtab[i].value) != 0) { len = snprintf(cp, sizeof(buf) - (cp - buf), "%s%s", cp > buf ? "|" : "", flagtab[i].name); - if (len < 0 || len >= sizeof(buf) - (cp - buf)) + if (len < 0 || (size_t)len >= sizeof(buf) - (cp - buf)) FATAL("out of space in flags2str"); cp += len; }