summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgmcgarry <gmcgarry>2009-08-13 08:01:27 +0000
committergmcgarry <gmcgarry>2009-08-13 08:01:27 +0000
commit6973828c20f1f6dfeec2282258180ceaaa5017ab (patch)
tree36a58620df6404f8bce6ecc468959967eba9a84f
parent655788eece47459d2c5593f30d147ff9b436587a (diff)
Add -Wtruncate option which detects truncation of types during assignment.
Let pcc compile with this option enabled. Inspired by similar warning in the Microsoft compiler.
-rw-r--r--cpp.c11
-rw-r--r--token.c39
2 files changed, 26 insertions, 24 deletions
diff --git a/cpp.c b/cpp.c
index 7af49d5..81fb1bd 100644
--- a/cpp.c
+++ b/cpp.c
@@ -455,7 +455,7 @@ line()
if ((c = yylex()) != NUMBER)
goto bad;
- ifiles->lineno = yylval.node.nd_val - 1;
+ ifiles->lineno = (int)(yylval.node.nd_val - 1);
if ((c = yylex()) == '\n')
return;
@@ -931,7 +931,7 @@ void
savch(int c)
{
if (stringbuf-sbf < SBSIZE) {
- *stringbuf++ = c;
+ *stringbuf++ = (usch)c;
} else {
stringbuf = sbf; /* need space to write error message */
error("Too much defining");
@@ -1029,7 +1029,7 @@ struct recur *rp;
nl = 0;
do {
c = cinput();
- *stringbuf++ = c;
+ *stringbuf++ = (usch)c;
if (c == WARN) {
gotwarn++;
if (rp == NULL)
@@ -1498,7 +1498,7 @@ flbuf()
void
putch(int ch)
{
- outbuf[obufp++] = ch;
+ outbuf[obufp++] = (usch)ch;
if (obufp == CPPBUF || (istty && ch == '\n'))
flbuf();
}
@@ -1530,7 +1530,8 @@ num2str(int num)
if (num < 0)
num = -num, m = 1;
do {
- *b++ = num % 10 + '0', num /= 10;
+ *b++ = (usch)(num % 10 + '0');
+ num /= 10;
} while (num);
if (m)
*b++ = '-';
diff --git a/token.c b/token.c
index f82ef35..a4d967c 100644
--- a/token.c
+++ b/token.c
@@ -131,7 +131,7 @@ unch(int c)
--ifiles->curptr;
if (ifiles->curptr < ifiles->bbuf)
error("pushback buffer full");
- *ifiles->curptr = c;
+ *ifiles->curptr = (usch)c;
}
/*
@@ -290,7 +290,7 @@ con: PUTCH(ch);
}
i = 0;
do {
- yytext[i++] = ch;
+ yytext[i++] = (usch)ch;
ch = NXTCH();
if (ch < 0)
return;
@@ -316,7 +316,8 @@ sloscan()
zagain:
yyp = 0;
- yytext[yyp++] = ch = inch();
+ ch = inch();
+ yytext[yyp++] = (usch)ch;
switch (ch) {
case -1:
return 0;
@@ -335,16 +336,16 @@ zagain:
ppnum: for (;;) {
ch = inch();
if (spechr[ch] & C_EP) {
- yytext[yyp++] = ch;
+ yytext[yyp++] = (usch)ch;
ch = inch();
if (ch == '-' || ch == '+') {
- yytext[yyp++] = ch;
+ yytext[yyp++] = (usch)ch;
} else
unch(ch);
continue;
}
if ((spechr[ch] & C_ID) || ch == '.') {
- yytext[yyp++] = ch;
+ yytext[yyp++] = (usch)ch;
continue;
}
break;
@@ -358,8 +359,8 @@ ppnum: for (;;) {
chlit:
for (;;) {
if ((ch = inch()) == '\\') {
- yytext[yyp++] = ch;
- yytext[yyp++] = inch();
+ yytext[yyp++] = (usch)ch;
+ yytext[yyp++] = (usch)inch();
continue;
} else if (ch == '\n') {
/* not a constant */
@@ -368,7 +369,7 @@ chlit:
ch = '\'';
goto any;
} else
- yytext[yyp++] = ch;
+ yytext[yyp++] = (usch)ch;
if (ch == '\'')
break;
}
@@ -381,7 +382,7 @@ chlit:
case ' ':
case '\t':
while ((ch = inch()) == ' ' || ch == '\t')
- yytext[yyp++] = ch;
+ yytext[yyp++] = (usch)ch;
unch(ch);
yytext[yyp] = 0;
return(WSPACE);
@@ -389,7 +390,7 @@ chlit:
case '/':
if ((ch = inch()) == '/') {
do {
- yytext[yyp++] = ch;
+ yytext[yyp++] = (usch)ch;
ch = inch();
} while (ch && ch != '\n');
yytext[yyp] = 0;
@@ -430,7 +431,7 @@ chlit:
case '.':
ch = inch();
if (isdigit(ch)) {
- yytext[yyp++] = ch;
+ yytext[yyp++] = (usch)ch;
goto ppnum;
} else {
unch(ch);
@@ -442,11 +443,11 @@ chlit:
strng:
for (;;) {
if ((ch = inch()) == '\\') {
- yytext[yyp++] = ch;
- yytext[yyp++] = inch();
+ yytext[yyp++] = (usch)ch;
+ yytext[yyp++] = (usch)inch();
continue;
} else
- yytext[yyp++] = ch;
+ yytext[yyp++] = (usch)ch;
if (ch == '\"')
break;
}
@@ -455,10 +456,10 @@ chlit:
case 'L':
if ((ch = inch()) == '\"') {
- yytext[yyp++] = ch;
+ yytext[yyp++] = (usch)ch;
goto strng;
} else if (ch == '\'') {
- yytext[yyp++] = ch;
+ yytext[yyp++] = (usch)ch;
goto chlit;
}
unch(ch);
@@ -481,7 +482,7 @@ chlit:
for (;;) { /* get chars */
ch = inch();
if (isalpha(ch) || isdigit(ch) || ch == '_') {
- yytext[yyp++] = ch;
+ yytext[yyp++] = (usch)ch;
} else {
unch(ch);
break;
@@ -1129,7 +1130,7 @@ ppdir(void)
goto out; /* something else, ignore */
i = 0;
do {
- bp[i++] = ch;
+ bp[i++] = (usch)ch;
if (i == sizeof(bp)-1)
goto out; /* too long */
ch = inch();