ref: 6394e7a9cdf65e35718af27855726192c3af5eaa
parent: 30e8cd88ec77114dd0bf67d26364dcbb6bc1ebf0
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Tue Sep 12 04:33:34 EDT 2017
[cc1] Remove scalar use of char Using scalar char is a bad idea because char are always promoted to int in all the operations, they use the same space than an int in the stack and since they may be signed, any operation over them bigger than 127 produces an overflow with undefined behaviour.
--- a/cc1/cc1.h
+++ b/cc1/cc1.h
@@ -412,7 +412,7 @@
extern void decl(void);
/* lex.c */
-extern char ahead(void);
+extern int ahead(void);
extern unsigned next(void);
extern void expect(unsigned tok);
extern void discard(void);
--- a/cc1/code.c
+++ b/cc1/code.c
@@ -188,7 +188,7 @@
static void
emitvar(Symbol *sym)
{
- char c;
+ int c;
short flags = sym->flags;
if (flags & SLOCAL)
--- a/cc1/cpp.c
+++ b/cc1/cpp.c
@@ -184,7 +184,8 @@
static size_t
copymacro(char *buffer, char *s, size_t bufsiz, char *arglist[])
{
- char delim, prevc, c, *p, *arg, *bp = buffer;
+ int delim, prevc, c;
+ char *p, *arg, *bp = buffer;
size_t size;
for (prevc = '\0'; c = *s; prevc = c, ++s) {
@@ -797,7 +798,8 @@
void
outcpp(void)
{
- char c, *s, *t;
+ int c;
+ char *s, *t;
for (next(); yytoken != EOFTOK; next()) {
if (onlyheader)
--- a/cc1/lex.c
+++ b/cc1/lex.c
@@ -377,7 +377,7 @@
}
static unsigned
-integer(char *s, char base)
+integer(char *s, int base)
{
Type *tp;
Symbol *sym;
@@ -414,7 +414,8 @@
static char *
digits(unsigned base)
{
- char c, *p;
+ char *p;
+ int c;
for (p = input->p; c = *p; ++p) {
switch (base) {
@@ -441,7 +442,7 @@
static unsigned
number(void)
{
- char base;
+ int base;
if (*input->p != '0') {
base = 10;
@@ -457,7 +458,7 @@
return integer(digits(base), base);
}
-static char
+static int
escape(void)
{
int c, base;
@@ -506,7 +507,7 @@
static unsigned
character(void)
{
- char c;
+ int c;
Symbol *sym;
if ((c = *++input->p) == '\\')
@@ -530,7 +531,8 @@
static unsigned
string(void)
{
- char *bp = yytext, c;
+ char *bp = yytext;
+ int c;
*bp++ = '"';
for (++input->p; (c = *input->p) != '"'; ++input->p) {
@@ -614,7 +616,7 @@
static unsigned
relational(int op, int equal, int shift, int assig)
{
- char c;
+ int c;
if ((c = *input->p++) == '=')
return equal;
@@ -627,7 +629,7 @@
static unsigned
logic(int op, int equal, int logic)
{
- char c;
+ int c;
if ((c = *input->p++) == '=')
return equal;
@@ -640,7 +642,7 @@
static unsigned
dot(void)
{
- char c;
+ int c;
if ((c = *input->p) != '.')
return '.';
@@ -753,7 +755,7 @@
}
}
-char
+int
ahead(void)
{
skipspaces();
@@ -770,7 +772,7 @@
discard(void)
{
extern jmp_buf recover;
- char c;
+ int c;
input->begin = input->p;
for (c = yytoken; ; c = *input->begin++) {
--- a/cc1/symbol.c
+++ b/cc1/symbol.c
@@ -276,8 +276,8 @@
lookup(int ns, char *name, int alloc)
{
Symbol *sym;
- int sns;
- char *t, c;
+ int sns, c;
+ char *t;
c = *name;
for (sym = *hash(name, ns); sym; sym = sym->hash) {