Remove compiler warnings when building Bionic.
Also add missing declarations to misc. functions.
Fix clearerr() implementation (previous was broken).
Handle feature test macros like _POSIX_C_SOURCE properly.
Change-Id: Icdc973a6b9d550a166fc2545f727ea837fe800c4
diff --git a/libc/regex/engine.c b/libc/regex/engine.c
index 66be3c7..eae6ff2 100644
--- a/libc/regex/engine.c
+++ b/libc/regex/engine.c
@@ -209,7 +209,7 @@
STATETEARDOWN(m);
return(REG_ESPACE);
}
- for (i = 1; i <= m->g->nsub; i++)
+ for (i = 1; i <= (int)m->g->nsub; i++)
m->pmatch[i].rm_so = m->pmatch[i].rm_eo = -1;
if (!g->backrefs && !(m->eflags®_BACKR)) {
NOTE("dissecting");
@@ -267,8 +267,8 @@
}
if (nmatch > 1) {
assert(m->pmatch != NULL);
- for (i = 1; i < nmatch; i++)
- if (i <= m->g->nsub)
+ for (i = 1; i < (ssize_t)nmatch; i++)
+ if (i <= (int)m->g->nsub)
pmatch[i] = m->pmatch[i];
else {
pmatch[i].rm_so = -1;
diff --git a/libc/regex/regcomp.c b/libc/regex/regcomp.c
index 5b632c8..19f4790 100644
--- a/libc/regex/regcomp.c
+++ b/libc/regex/regcomp.c
@@ -249,8 +249,8 @@
p_ere(struct parse *p, int stop) /* character this ERE should end at */
{
char c;
- sopno prevback;
- sopno prevfwd;
+ sopno prevback = 0;
+ sopno prevfwd = 0;
sopno conc;
int first = 1; /* is this the first alternative? */
@@ -767,7 +767,7 @@
p_b_cclass(struct parse *p, cset *cs)
{
char *sp = p->next;
- struct cclass *cp;
+ const struct cclass *cp;
size_t len;
char *u;
char c;
@@ -831,7 +831,7 @@
int endc) /* name ended by endc,']' */
{
char *sp = p->next;
- struct cname *cp;
+ const struct cname *cp;
int len;
while (MORE() && !SEETWO(endc, ']'))
@@ -1084,7 +1084,7 @@
cset *top = &p->g->sets[p->g->ncsets];
size_t css = (size_t)p->g->csetsize;
- for (i = 0; i < css; i++)
+ for (i = 0; i < (ssize_t)css; i++)
CHsub(cs, i);
if (cs == top-1) /* recover only the easy case */
p->g->ncsets--;
@@ -1112,10 +1112,10 @@
for (cs2 = &p->g->sets[0]; cs2 < top; cs2++)
if (cs2->hash == h && cs2 != cs) {
/* maybe */
- for (i = 0; i < css; i++)
+ for (i = 0; i < (ssize_t)css; i++)
if (!!CHIN(cs2, i) != !!CHIN(cs, i))
break; /* no */
- if (i == css)
+ if (i == (ssize_t)css)
break; /* yes */
}
@@ -1136,7 +1136,7 @@
int i;
size_t css = (size_t)p->g->csetsize;
- for (i = 0; i < css; i++)
+ for (i = 0; i < (ssize_t)css; i++)
if (CHIN(cs, i))
return((char)i);
assert(never);
@@ -1153,7 +1153,7 @@
size_t css = (size_t)p->g->csetsize;
int n = 0;
- for (i = 0; i < css; i++)
+ for (i = 0; i < (ssize_t)css; i++)
if (CHIN(cs, i))
n++;
return(n);
@@ -1412,7 +1412,7 @@
findmust(struct parse *p, struct re_guts *g)
{
sop *scan;
- sop *start; /* start initialized in the default case, after that */
+ sop *start = NULL; /* start initialized in the default case, after that */
sop *newstart; /* newstart was initialized in the OCHAR case */
sopno newlen;
sop s;
diff --git a/libc/regex/regerror.c b/libc/regex/regerror.c
index 894a939..838ec8f 100644
--- a/libc/regex/regerror.c
+++ b/libc/regex/regerror.c
@@ -78,7 +78,7 @@
size_t
regerror(int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size)
{
- struct rerr *r;
+ const struct rerr *r;
size_t len;
int target = errcode &~ REG_ITOA;
char *s;
@@ -117,7 +117,7 @@
static char *
regatoi(const regex_t *preg, char *localbuf, int localbufsize)
{
- struct rerr *r;
+ const struct rerr *r;
for (r = rerrs; r->code != 0; r++)
if (strcmp(r->name, preg->re_endp) == 0)
diff --git a/libc/regex/regexec.c b/libc/regex/regexec.c
index 7b3bfc7..6feed3b 100644
--- a/libc/regex/regexec.c
+++ b/libc/regex/regexec.c
@@ -153,7 +153,7 @@
return(REG_BADPAT);
eflags = GOODFLAGS(eflags);
- if (g->nstates <= CHAR_BIT*sizeof(states1) && !(eflags®_LARGE))
+ if (g->nstates <= (int)(CHAR_BIT*sizeof(states1)) && !(eflags®_LARGE))
return(smatcher(g, (char *)string, nmatch, pmatch, eflags));
else
return(lmatcher(g, (char *)string, nmatch, pmatch, eflags));